The coding code that calls getListCellRendererComponent then calls setForeground and setBackground on the returned component (depending on whether the component is selected and / or focused). I guess this is for some kind of legacy. Unfortunately, this defeats the purpose of my install in the renderer.
I had good results with this approach:
The code below bypasses the changes in the foreground and background by overriding the fg / bg setters to do nothing, then I just call the super implementations to set the desired colors.
public static class CustomRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); super.setBackground(Color.WHITE); super.setForeground(Color.BLACK); return this; } public void setForeground(Color c) {} public void setBackground(Color c) {} }
Addendum: Obviously, the gray border is the border. Try the same approach, but also override setBorder .
source share