In the company where I work, we derived a class from sun.awt.WToolkit
to change some of the colors by calling setDesktopProperty()
. And that worked fine for years. But now in JDK 8, WToolkit is final and cannot be subclassed. The easy way out could be doing some nasty reflection and call the protected method, though I'm not sure that this won't yield a security exception or something similar.
The right way out is to change these colors through the Look and Feel. Oracle in Windows Desktop Property Support states that
Programs do not need to access these properties directly; the Windows look and feel will automatically read and interpret these properties to provide proper visuals and behavior for the components.
But it does not state anything about customizing these properties through LaF modifications and certainly doing UIManager.put("win.3d.shadowColor", Color.gray);
as it's mentioned in this doc is ineffective.
So my question is, can Windows Desktop Properties be changed by subclassing an existing Look and Feel, or should I resort to some kind of a hack?
Swing’s Windows Look&Feel will import the Window-specific desktop properties into its defaults table, but within this table, the standard, LaF-independent names are used which are usually composed from the component’s name and the property.
E.g.:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(ClassNotFoundException|InstantiationException
|IllegalAccessException|UnsupportedLookAndFeelException ex) {
Logger.getLogger(LaFColors.class.getName()).log(Level.SEVERE, null, ex);
System.exit(1);
}
UIManager.put("Panel.background", Color.YELLOW);
UIManager.put("Button.foreground", Color.BLUE);
JFrame frame=new JFrame("Test");
frame.getContentPane().add(new JButton("See, it’s still "
+UIManager.getLookAndFeel().getName()+" LaF"), BorderLayout.NORTH);
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);