gpt4 book ai didi

java - JMenuBar 在 Mac OS X Lion 上不显示,但在 Win7 上显示

转载 作者:行者123 更新时间:2023-11-30 04:53:13 24 4
gpt4 key购买 nike

帖子标题已经解释了我的问题所在。这是一个已知的错误?我在网上搜索但找不到解决方案。

那么,你知道该怎么做吗?

public static void main(String[] args) {
JFrame frame = new JFrame("Menu");
frame.setVisible(true);
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JMenuBar menubar = new JMenuBar();
frame.setJMenuBar(menubar);

JMenu file = new JMenu("File");
menubar.add(file);
JMenuItem exit = new JMenuItem("Exit");
file.add(exit);

JMenu help = new JMenu("Help");
menubar.add(help);
JMenuItem about = new JMenuItem("About");
help.add(about);

class exitAction implements ActionListener {

public void actionPerformed(ActionEvent e){
System.exit(0);
}
}

exit.addActionListener(new exitAction());
}

最佳答案

1) 你的代码行

frame.setVisible(true);

必须是main方法中的最后一行代码

2) Swing GUI 不是线程安全的,那么 main 方法 应包装到 invokeLater()

关于java - JMenuBar 在 Mac OS X Lion 上不显示,但在 Win7 上显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9417877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com