> I need a JList that displays items which consist of an image and some
> text. For this purpose I wrote my own ListCellRenderer which did the
[quoted text clipped - 4 lines]
> soon as MyListCellRenderer is set as the default cell renderer then no
> highlighting is there.
Have you checked what the colours are that you are getting from list.getSelectionBackground() and
list.getSelectionForeground()?
It might be worth hard-coding some colours for testing purposes as the list might be supplying colours which are
the same for FG and BG.
The DefaultListCellRenderer doesn't do much different from your code except at the start it does...
setComponentOrientation(list.getComponentOrientation());
and at the end it does...
setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
and it does this in the constructor...
noFocusBorder = new EmptyBorder(1, 1, 1, 1);
setOpaque(true);
setBorder(noFocusBorder);
I can't see any of that affecting colours except perhaps the setOpaque().
It might be easier to subclass DefaultListCellRenderer and write the method (assuming value is an Icon) as...
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
{
super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus);
setText(value.toString());
}
> Any help appreciated.
>
[quoted text clipped - 23 lines]
> }
> }
Tom N - 07 Jul 2005 03:08 GMT
> public Component getListCellRendererComponent(
> JList list,
[quoted text clipped - 5 lines]
> super.getListCellRendererComponent( list, value, index,
> isSelected, cellHasFocus); setText(value.toString());
return this;
> }
Scott Steiner - 07 Jul 2005 08:35 GMT
[...]
> It might be easier to subclass DefaultListCellRenderer and write the method (assuming value is an Icon) as...
>
[quoted text clipped - 8 lines]
> setText(value.toString());
> }
[...]
Thanks Tom! Subclassing DefaultListCellRenderer and calling
super.getListCellRendererComponent was the solution to my problem.