2012-02-23 14 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

にラップする必要がありますすべての要素を追加したら、メニューバーを設定してみてください。 –

答えて

2

1)あなたのコード行

frame.setVisible(true); 

はスレッドセーフではありませんmain method

2)Swing GUIでの最後のコード行にする必要があり、その後、main methodinvokeLater()

+0

ありがとうございます。それはうまくいった! – Baloo

関連する問題