• Post Reply Bookmark Topic Watch Topic
  • New Topic

Selecting cells in JList  RSS feed

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to use getListCellRendererComponent
to set a to JList cells depending upon the type of data in them. This is working, however, when I
select the different rows in the JList it doesn't
highlight the row. Can anyone tell me how to accomplish this?
Thanks.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should modify the Component you return in getListCellRendererComponent depending on whether or not the item is selected.
For example, you can set the background color to be different if isSelected (a boolean argument) is true.
If you are using a DefaultListCellRenderer (or subclass), you can use setBackground. If you are using a straight-up JLabel (or subclass), you should setOpaque(true) first to get the background to show.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!