0

I have a custom JList renderer that has an image and some labels. I know how to set the background and foreground of this list using the isSelected variable and the UIManager default L&F.

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        panel.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
        panel.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());

This works fine but I am unsure about the JLabel's colors though, since there is "selected" color key. As such when the item is selected it doesn't change color and has little contrast.

I found a list of keys I can use to get data from UIManager but I'm not sure which ones are used for "selected JList item label".

For example on OSX the default is white background with black text. However on selection the cell background is blue and the text becomes white. I want to know how to lookup what color the label turns to (in this case, white). Foreground/background/disabled are the only ones I can find.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Mgamerz
  • 2,872
  • 2
  • 27
  • 48
  • List.selectionBackground and List.selectionForeground. Generally, this won't effect the icon/image itself – MadProgrammer Jun 13 '15 at 03:26
  • @MadProgrammer Is this not the same as the code I already posted? I'm looking for the label ones not the list background ones. The label and the list have different colors for selected and different for non selected. – Mgamerz Jun 13 '15 at 03:28
  • 1
    Labels don't have any different colors unless you define them, but default, the DefaultListCellRenderer uses these key values (and caches them) – MadProgrammer Jun 13 '15 at 04:47

0 Answers0