Unable to change SystemLookAndFeel under Windows 7

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(); } // Setup panel JPanel mainPanel = new JPanel(); mainPanel.setBackground( Color.white ); mainPanel.setLayout( new BorderLayout() ); mainPanel.setOpaque( true ); this.getContentPane().add( mainPanel, BorderLayout.CENTER ); // Create menubar JMenuBar menuBar = new JMenuBar(); getContentPane().add(menuBar, BorderLayout.NORTH); // Add menu JMenu m_file = new JMenu( "File" ); menuBar.add( m_file ); // Add menu items m_file.add( new JMenuItem( "First item" ) ); m_file.add( new JMenuItem( "Second item" ) ); } public void start() {} public void stop() {} public void destroy() {} } 
+4
source share
3 answers

I got my question in the Oracle Java Forum :

LookAndFeels is not required to use any specific UIManager properties.

This seems to be too right.

Martin.

0
source

Martin, you can use this instead

 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"); 
+2
source

Windows 7 can use NimbusLookAndFeel , which has its own defaults and other way to define colors .

Application: If not, you may need to specify a ColorUIResource , for example

 UIManager.put("MenuBar.background", new ColorUIResource(Color.decode("#efecea"))); 
+1
source

All Articles