Creating a JMenuBar, JMenu, and JMenuItem Component

When the user selects a menu item, it fires an action event.
// Create the menu bar JMenuBar menuBar = new JMenuBar(); // Create a menu JMenu menu = new JMenu("Menu Label"); menuBar.add(menu); // Create a menu item JMenuItem item = new JMenuItem("Item Label"); item.addActionListener(actionListener); menu.add(item); // Install the menu bar in the frame frame.setJMenuBar(menuBar);

Comments

10 Mar 2010 - 10:13pm by Archielsie (not verified)

meaning about JMenu class

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.