I'm struggling with a descriptive title.
I'm trying to use the swing.plaf colors from NimbusLookAndFeel in a custom component of mine. The colors i'm getting from UIManager looks good, but the setBackground and setForeground methods doesn't work with the colors im getting.
The following sample displays the very curious behaviour
package syscolorbug;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class SysColorBug {
public static void main(String[] args) throws Exception {
javax.swing.UIManager.
setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
Color background = javax.swing.UIManager.getDefaults().
getColor("List[Selected].textBackground");
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setLayout(new FlowLayout());
jf.setSize(400,300);
JLabel l = new JLabel("Text");
l.setOpaque(true);
jf.add(l);
System.err.println(background);
// This needs to happen for the color to be set.
//24: background = new Color(background.getRGB());
System.err.println(background);
l.setBackground(background);
jf.setVisible(true);
}
}
If i comment out 24: it works as intended.
The debug output on background shows
DerivedColor(color=57,105,138 parent=nimbusSelectionBackground offsets=0.0,0.0,0.0,0 pColor=57,105,138
and
java.awt.Color[r=57,g=105,b=138]
Further investigations shows that the problem doesn't seem to be affecting other LookAndFeels.
For instance on the Metal LAF produces
javax.swing.plaf.ColorUIResource[r=255,g=255,b=255]
for the 'List.background' key.
Is this a bug in the Nimbus plaf?
I'd very much like to avoid the superflous background = new Color(background.getRGB()); is there an easy fix?
Java version is openjdk java 1.8.0.
I don't do laf much when I do graphics so I don't understand why
List[Selected].textBackgroundwould be the background of theJLabel. The default appears to becolor=214,217,223This also seems to match what I saw and read at nimbus laf