Baloo
Baloo

Reputation: 221

JMenuBar doesn't display on Mac OS X Lion but does on Win7

the thread title already explains what my problem is. Is this a known bug? I searched the internet but couldn't find a solution.

So, do you maybe know what to do?

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

Upvotes: 1

Views: 335

Answers (1)

mKorbel
mKorbel

Reputation: 109813

1) your code line

frame.setVisible(true);

must be last code line in the main method

2) Swing GUI isn't thread safe, then main method should be wrapped into invokeLater()

Upvotes: 2

Related Questions