[英]JMenuBar causes content pane to repaint incorrectly
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. 我在使用JMenuBar时遇到一个非常奇怪的问题,其中在两个JMenus之间导航会导致菜单所属的JFrame的contentPane错误地重新绘制。 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.
在空的contentPane与普通的背景颜色之间进行切换需要花费几秒钟的时间。
EDIT To clarify, this is on Windows 7 using JDK 1.7.0. 编辑要澄清一下,这是在Windows 7上使用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: 然后在使用JMenus几秒钟后:
Below is a SSCCE demonstrating the problematic code. 下面是一个SSCCE,演示有问题的代码。
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);
}
});
}
}
It must be a platform-specific thing. 它必须是特定于平台的东西。 The GUI appeared fine on my machine: Ubuntu 11.10, Eclipse 3.7, Sun JDK 7.
该GUI在我的机器上看起来不错:Ubuntu 11.10,Eclipse 3.7,Sun JDK 7。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.