Java Reference
In-Depth Information
Using Mnemonics and Accelerators
The Swing libraries also use KeyStroke objects for several internal functions. Two such functions
are component mnemonics and accelerators, which work as follows:
In a component mnemonic , one character in a label appears underlined. When that
character is pressed along with a platform-specific hotkey combination, the component
is activated. For instance, pressing Alt-A in the window shown in Figure 2-8 would select
the About button on a Windows XP platform.
•A menu accelerator activates a menu item when it is not visible. For instance, pressing
Ctrl-P would select the Print menu item in the window shown in Figure 2-8 when the File
menu isn't visible.
Figure 2-8. Mnemonics and menu shortcuts
You'll learn more about mnemonics and accelerators in Chapter 6.
Swing Focus Management
The term focus refers to when a component acquires the input focus. When a component has
the input focus, it serves as the source for all key events, such as text input. In addition, certain
components have some visual markings to indicate that they have the input focus, as shown in
Figure 2-9. When certain components have the input focus, you can trigger selection with a
keyboard key (usually the spacebar or Enter key), in addition to selection with a mouse. For
instance, with a button, pressing the spacebar activates it.
Figure 2-9. A JButton showing it has input focus
 
Search WWH ::




Custom Search