2012-02-23 82 views
1

线程标题已经解释了我的问题。这是一个已知的错误?我搜索了互联网,但找不到解决方案。JMenuBar不显示在Mac OS X Lion上,但在Win7上显示

那么,你可能知道该怎么办?

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()); 
} 
+0

尝试在添加完所有元素后设置菜单栏。 – 2012-02-23 17:27:47

回答

2

1)你的代码行

frame.setVisible(true); 

必须在main method

2)Swing GUI最后行代码不是线程安全的,那么main method应该被包装成invokeLater()

+0

谢谢。这工作! – Baloo 2012-02-23 17:34:09