| |
e808. 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);
e809.
Separating Menu Items in a Menu
e810.
Creating a Popup Menu
e811.
Creating a Popup Menu with Nested Menus
e812.
Forcing a Popup Menu to Be a Heavyweight Component
e813.
Getting the Currently Selected Menu or Menu Item
e814.
Creating a Menu Item That Listens for Changes to Its Selection Status
e815.
Listening for Changes to the Currently Selected Menu or Menu Item
© 2002 Addison-Wesley.
|