I seem to have done everything correct. I just need to implement a simple JMenuBar
but it seems to be not working. Can someone please help me out in this?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class swing {
public static void main (String[] args) {
JFrame frame = new JFrame ("menu");
frame.setVisible (true);
frame.setSize (400, 400);
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JMenuBar bar = new JMenuBar ();
frame.setJMenuBar (bar);
bar.setVisible (true);
JMenu file = new JMenu ("File");
bar.add (file);
JMenuItem open = new JMenuItem ("open");
file.add(open);
}
}
revalidate
on the container. – Greenhaw