Reputation: 12766
I've encountered a very strange issue using JMenuBar where navigating between two JMenus results in the contentPane of the JFrame which the menu belongs to to repaint incorrectly. The content pane presents the correct background only where the menu items drop down and 'dirty' the screen -- the rest is entirely white. However, this only occurs after browsing between the two menus, and not right away. It takes a few seconds of switching between for the empty contentPane to change from the ordinary background color.
EDIT To clarify, this is on Windows 7 using JDK 1.7.0.
To better illustrate what I mean, here is the window after launch (manually resized):
And then after using the JMenus for a few seconds:
Below is a SSCCE demonstrating the problematic code.
package com.test.workspace;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
public class MenuBarTest extends JFrame {
/**
* Eclipse-generated SUID.
*/
private static final long serialVersionUID = 8836700685077107497L;
public MenuBarTest() {
JMenuBar menuBar = new JMenuBar();
JMenu testMenu = new JMenu("Test");
JMenuItem testItem = new JMenuItem("TestItem");
JMenu breakMenu = new JMenu("Break");
JMenuItem breakItem = new JMenuItem("BreakItem");
testMenu.add(testItem);
breakMenu.add(breakItem);
menuBar.add(testMenu);
menuBar.add(breakMenu);
this.setJMenuBar(menuBar);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
MenuBarTest test = new MenuBarTest();
test.setDefaultCloseOperation(EXIT_ON_CLOSE);
test.pack();
test.setVisible(true);
}
});
}
}
Upvotes: 2
Views: 486
Reputation: 3190
It must be a platform-specific thing. The GUI appeared fine on my machine: Ubuntu 11.10, Eclipse 3.7, Sun JDK 7.
Upvotes: 1