I have a JList object with several items in it. When I select an item, its
colors change in the following way:
- background changes from white to blue
- foreground changes from black to white
- the selected item gets a yellow border around it
The background and foreground colors I can handle with setBacground() and
setForeground methods,
no problem, but how can I get rid of the yellow border around the selection
(or change its color) ?
Thanks,
KT
> but how can I get rid of the yellow border around the selection
> (or change its color) ?
Simplest is to use the Swing properties (if you want it for all JLists):
UIManager.put("List.focusCellHighlightBorder", yourBorder);
Actually, the background, foreground, and yellow border are
created in one place. JList uses a DefaultListCellRenderer
object to create the list items. You need to create a
DefaultListCellRenderer subclass, and use setRenderer() to tell
your list to use the new customized renderer. Your custom
renderer should override the getListCellRendererComponent()
method to return a Component that looks correct. Just take a
look at the existing getListCellRendererComponent() method. It's
very straightforward, and you should be able to easily modify it
to suit your needs.
Jim S.
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com