I'm currently trying to write custom ListCellRendererfor JList. Unfortunately, almost all of the examples are simply used DefaultListCellRendereras JLabeldone; However, I needed it JPanel(since I need to display a little more information than just an icon and one line of text).
Now I have a problem with background colors, especially with Nimbus PLAF. Apparently, the background color that I get from list.getBackground()is white, but is painted a shade of gray (or bluish-gray). The color output that I get gives the following:
Background color: DerivedColor (color = 255,255,255 parent = nimbusLightBackground offsets = 0.0,0.0,0.0,0 pColor = 255,255,255
However, as you can see, this is not something that is painted.

This clearly works for the selected item. Currently, I even have every component that I inserted in JPanel, the cell renderer returns opaque and with the correct foreground and background colors - to no avail.
Any idea what I'm doing wrong here?
ETA: Sample code that I hope is executing.
public class ParameterListCellRenderer implements ListCellRenderer {
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
Border border = null;
Color foreground, background;
if (isSelected) {
background = list.getSelectionBackground();
foreground = list.getSelectionForeground();
} else {
background = list.getBackground();
foreground = list.getForeground();
}
if (cellHasFocus) {
if (isSelected) {
border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
}
if (border == null) {
border = UIManager.getBorder("List.focusCellHighlightBorder");
}
} else {
border = UIManager.getBorder("List.cellNoFocusBorder");
}
System.out.println("Background color: " + background.toString());
JPanel outerPanel = new JPanel(new BorderLayout());
setProperties(outerPanel, foreground, background);
outerPanel.setBorder(border);
JLabel nameLabel = new JLabel("Factory name here");
setProperties(nameLabel, foreground, background);
outerPanel.add(nameLabel, BorderLayout.PAGE_START);
Box innerPanel = new Box(BoxLayout.PAGE_AXIS);
setProperties(innerPanel, foreground, background);
innerPanel.setAlignmentX(Box.LEFT_ALIGNMENT);
innerPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
JLabel label = new JLabel("param: value");
label.setFont(label.getFont().deriveFont(
AffineTransform.getScaleInstance(0.95, 0.95)));
setProperties(label, foreground, background);
innerPanel.add(label);
outerPanel.add(innerPanel, BorderLayout.CENTER);
return outerPanel;
}
private void setProperties(JComponent component, Color foreground,
Color background) {
component.setOpaque(true);
component.setForeground(foreground);
component.setBackground(background);
}
}
Strange thing if i do
if (isSelected) {
background = new Color(list.getSelectionBackground().getRGB());
foreground = new Color(list.getSelectionForeground().getRGB());
} else {
background = new Color(list.getBackground().getRGB());
foreground = new Color(list.getForeground().getRGB());
}
it works magically. So, maybe, DerivedColorwith nimbusLightBackgroundthat I get can be a problem?