Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Border color around selection in JList

401 views
Skip to first unread message

Kari Heikkilä

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
Hi!

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


Tor Iver Wilhelmsen

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
"Kari Heikkilä" <kari.h...@vaisala.com> writes:

> 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);

jsculley

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
"Kari Heikkilä" <kari.h...@vaisala.com> wrote:
>Hi!
>
>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) ?
>

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


0 new messages