【发布时间】:2012-09-03 16:08:37
【问题描述】:
如果单击另一个组件时弹出菜单仍然打开,则该组件不会收到事件,因为它可能已被弹出窗口消耗。一般情况下,所有 JPopupmenus 都会发生这种情况。 这只发生在带有 Windows LAF (Windows7) 的 Java 7 中。有解决方法吗?这是一个已知的错误吗?
import javax.swing.*;
import java.awt.event.*;
public class Test
{
public static void main(String[] s)
throws Exception
{
String lookAnfFeelClassName = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(lookAnfFeelClassName);
JMenu menu = new JMenu("TEST Menu");
JMenuItem menuItem = new JMenuItem("Menu Item 1");
JMenuBar menuBar = new JMenuBar();
menu.add(menuItem);
menuBar.add(menu);
final JButton b = new JButton("Test");
b.setBounds(5, 50, 60, 20);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//If the Menu is open when I press the button, the putton is not pressed
//so I have to press it again.
JOptionPane.showMessageDialog(b, "Button Pressed");
}
}
);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(150, 150);
frame.setJMenuBar(menuBar);
frame.getContentPane().setLayout(null);
frame.getContentPane().add(b);
frame.setVisible(true);
}
}
【问题讨论】:
-
请问JRE和JDK版本编译了什么???
-
JRE 版本 1.7.0_05-b05,但我可以用 JRE 1.6.0_23 重现它
-
在 Win7 上用 SystemLookAndFeel 重现???,嗯,等几分钟我要重新启动到 Win7
-
是的,在 windows7 中你会立即复制它
-
就在
Win7上,您必须两次单击JButton,在禁用SystemLookAndFeel后不会出现此问题,对于jdk1.6.0_25 和jdk1.7.0_04,我必须测试在WinXP和Java6
标签: java swing java-7 jmenu jpopupmenu