// create JMenu object JMenu menu = new JMenu("File"); // add items to the menu menu.add(new JMenuItem("Open")); menu.add(new JMenuItem("Save")); // remove all items menu.removeAll();
// create JMenuBar object JMenuBar bar = new JMenuBar(); // add JMenu objects to the bar JMenu fileMenu = new JMenu("File"); fileMenu.add(new JMenuItem("Open")); fileMenu.add(new JMenuItem("Save")); bar.add(fileMenu); JMenu editMenu = new JMenu("Edit"); editMenu.add(new JMenuItem("Cut")); editMenu.add(new JMenuItem("Copy")); editMenu.add(new JMenuItem("Paste")); bar.add(editMenu); // remove all JMenu objects from the bar bar.removeAll();In both examples, the removeAll() method is called on the JMenu object to remove all the items or on the JMenuBar object to remove all the menus. The package library is javax.swing.