Hello,
I'm experiencing a subtle issue with the Swing SystemLookAndFeel under Windows 7. The applet below sets the SystemLookAndFeel and then modifies the background colour of MenuBar and MenuItem. This works perfectly well with Windows XP and it works also well with Windows 7 having the Windows Classic theme activated. But it has no effect with the Windows 7 standard theme. Does anyone have an explanation for it?
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() {}
}