I'm writing my own ListCellRenderer for a JList, and I seem to be
running into a problem.
The code below (in getListCellRendererComponent) is supposed to (or so
I am told) appropriately change the color of the selected item so it
stands out (and conforms to a user's preferences, etc). However, when
I actually set the JList's ListCellRenderer to my custom renderer,
nothing happens to the background color or the foreground color. Can
anyone explain why?
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}

Signature
I am only a mirage.
ak - 28 Nov 2003 16:43 GMT
please post complete getListCellRendererComponent() method.
--
____________
http://reader.imagero.com the best java image reader.
> I'm writing my own ListCellRenderer for a JList, and I seem to be
> running into a problem.
[quoted text clipped - 16 lines]
> --
> I am only a mirage.
Lee Weiner - 28 Nov 2003 17:06 GMT
>I'm writing my own ListCellRenderer for a JList, and I seem to be
>running into a problem.
[quoted text clipped - 13 lines]
> setForeground(list.getForeground());
> }
Without seeing the whole method I'm only guessing, but I'll bet you didn't set
the label to be opaque.
setOpaque( true );
Lee Weiner
lee AT leeweiner DOT org
kelvSYC - 29 Nov 2003 02:10 GMT
> Without seeing the whole method I'm only guessing, but I'll bet you didn't
> set the label to be opaque.
That worked! But what does opacity do?

Signature
I am only a mirage.
Lee Weiner - 29 Nov 2003 02:24 GMT
>> Without seeing the whole method I'm only guessing, but I'll bet you didn't
>> set the label to be opaque.
>
>That worked! But what does opacity do?
A ListCellRenderer is basically a JLabel. The background of a JLabel is, by
default, transparent and doesn't display any color of its own, it displays the
background color of the component it's in. Setting it to be opaque allows it
to display its own background color.
Lee Weiner
lee AT leeweiner DOT org