Menus
A JMenu is a standard
pull-down menu with a fixed name. Menus can hold other menus as submenu
items, enabling you to implement complex menu structures. In Swing, menus
are first-class components, just like everything else. You can place them
any place a component would go. Another class, JMenuBar, holds menus in
the conventional horizontal bar. Menu bars are real components, too, so
you can place them any place you want in a container: top, bottom, or
middle. But in the middle of a container, it usually makes more sense to
use a JComboBox rather than some kind
of menu.
Menu items may have associated images and shortcut keys; there are even menu items that look like checkboxes and radio buttons. Menu items are really a kind of button. Like buttons, menu items fire action events when they are selected. You can respond to menu items by registering action listeners with them.
There are two ways to use the keyboard with menus. The first is called mnemonics. A mnemonic is one character in the menu name. If you hold down the Alt key and type a menu’s mnemonic, the menu drops down, just as if you had clicked on it with the mouse. Menu items may also have mnemonics. Once a menu is dropped down, you can select individual items in the same way.
Menu items may also have accelerators. An accelerator is a key combination that selects the menu item, whether or not the menu that contains it is showing. A common example is the accelerator Ctrl-C, which is frequently used as a shortcut for the ...