Hey, I've got some trouble with my code. It should be two tabs in the frame, with the titles "File" and "Open". But I can only see "File". I rewrote the code and launched it, and I could see both, then I changed size of the frame, and they were gone again. Sometimes I can see neither one, it's really weird. Here's the code, take a look at it and see if you can see any mistakes. And I'm using Dr Java and Eclipse, neither of them works.
import javax.swing.*;
public class Meny{
public static void main(String[] cmdLn){
JFrame f = new JFrame("Meny");
f.setVisible(true);
f.setSize(300,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
f.setJMenuBar(mb);
JMenu file = new JMenu("File");
mb.add(file);
JMenuItem exit = new JMenuItem();
file.add(exit);
JMenu open = new JMenu("Open");
mb.add(open);
}
}
I can't see what I've done wrong. Help would be appreciated.
Edit
All of a sudden I can see the two tabs, but I can't see the "exit" option in the tab "File". It's really weird.