DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007

    Coloring elements in JList or any other?


    Can we color items in a listbox.For example if there are two array of strings and i am displaying them in a listbox(JList). i need first array of strings in black and second array of strings in red color.Can we do that in java?

    We cannot directly do the same thing in VB with ListBox. for that we have to use ListView for coloring elements.

    So is there any component in java like vb has? Is it feasible?

    srinivasa kanchiraju

  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    Take a look at the API documentation for JList and you'll see a discussion about a ListCell Renderer interface. Your own implementation of the ListCellRenderer you associate with your JList can allow you to change the background, foreground, text color, etc. of the content of each of the cells in your list. This is another example of the separation of the manipulation of content (through a "Model") and the manipulation of presentation (through "Renderer" type interfaces) that you also find in JTables.

Similar Threads

  1. adding elements to a JList
    By anubis in forum Java
    Replies: 3
    Last Post: 02-02-2006, 04:50 PM
  2. Replies: 2
    Last Post: 12-27-2005, 01:39 AM
  3. Horizontal Dispaly of Images in JList
    By datechie in forum Java
    Replies: 3
    Last Post: 06-13-2005, 10:34 AM
  4. Scrollable Jlist
    By matt in forum Java
    Replies: 1
    Last Post: 12-04-2001, 10:44 AM
  5. Replies: 1
    Last Post: 07-12-2001, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.