I am having a subtle issue with Swing SystemLookAndFeel on Windows 7. The applet below sets SystemLookAndFeel and then changes the background color of MenuBar and MenuItem. This works fine with Windows XP, and it also works well with Windows 7 when the Windows Classic theme is activated. But this does not affect the standard Windows 7 theme. Does anyone have an explanation?
Regards, Martin.
import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JApplet; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; @SuppressWarnings("serial") public class Win7TestApplet extends JApplet { public void init() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.put("MenuBar.background", Color.decode( "#efecea" )); UIManager.put("MenuItem.background", Color.decode( "#9999ff" )); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); }
user346034
source share