Java Reference
In-Depth Information
Working with Menus
Let's begin with an example that demonstrates how all the menu components fit together.
To start, create a frame with a menu bar, as shown in Figure 6-1.
Accelerator
JMenu
Mnemonic
JMenuBar
JMenuItem
JRadioButtonMenuItem
JSeparator
JCheckBoxMenuItem
JPopupMenu
Figure 6-1. Menu component examples
This simple menuing example has the following features:
On the menu bar are two ubiquitous menus: File and Edit. Under the File menu, the
familiar options of New, Open, Close, and Exit will appear (although they aren't shown
in Figure 6-1). Under the Edit menu are options for Cut, Copy, Paste, and Find, and a
submenu of Find options. The Options submenu will contain choices for search direction—
forward or backward—and a toggle for case sensitivity.
In various places within the different menus, menu separators divide the options into
logical sets.
Each of the menu options has a mnemonic associated with it to help with keyboard
navigation and selection. The mnemonic allows users to make menu selections via the
keyboard, for instance, by pressing Alt-F on a Windows platform to open the File menu.
In addition to the keyboard mnemonic, a keystroke associated with several options acts
as a keyboard accelerator. Unlike the mnemonic, the accelerator can directly activate a
menu option, even when the menu option isn't visible.
The Options submenu has an icon associated with it. Although only one icon is shown in
Figure 6-1, all menu components can have an icon, except for the JSeparator and
JPopupMenu components.
Search WWH ::




Custom Search