MenuShortcut
MenuShortcut
is a class used to represent a keyboard shortcut for a MenuItem
. When these events occur, an action event is generated that triggers the menu component. When a shortcut is associated with a MenuItem
, the MenuItem
automatically displays a visual clue, which indicates that a keyboard accelerator is available.
MenuShortcut Methods
Constructors- public MenuShortcut (int key)
- The first
MenuShortcut
constructor creates aMenuShortcut
withkey
as its designated hot key. Thekey
parameter can be any of the virtual key codes from theKeyEvent
class (e.g.,VK_A
,VK_B
, etc.). These constants are listed in Table 4.4. To use the shortcut, the user must combine the givenkey
with a platform-specific modifier key. On Windows and Motif platforms, the modifier is the Control key; on the Macintosh, it is the Command key. For example, if the shortcut key is F1 (VK_F1
) and you're using Windows, you would press Ctrl+F1 to execute the shortcut. To find out the platform's modifier key, call theToolkit.getMenuShortcutKeyMask()
method. - public MenuShortcut(int key, boolean useShiftModifier)
- This
MenuShortcut
constructor creates aMenuShortcut
withkey
as its designated hot key. IfuseShiftModifier
istrue
, the Shift key must be depressed for this shortcut to trigger the action event (in addition to the shortcut key). Thekey
parameter represents the integer value of aKEY_PRESS
event, so in addition to ASCII values, possible values include the variousEvent
keyboard constants (listed in Table 4.2) likeEvent.F1
,Event.HOME
, andEvent.PAUSE
. For example, ifkey
is the ASCII value for A anduseShiftModifier
istrue
, the shortcut key is Shift+Ctrl+A on a Windows/Motif platform.
- public int getKey ()
- The
getKey()
method retrieves the virtual key code for the key that triggered thisMenuShortcut
. The virtual key codes are theVK
constants defined by theKeyEvent
class (see Table 4.4). - public boolean usesShiftModifier()
- The
usesShiftModifier()
method returnstrue
if thisMenuShortcut
requires the Shift key be pressed,false
otherwise. - public boolean equals(MenuShortcut s)
- The
equals()
method overridesObject
'sequals()
method to define equality for menu shortcuts. TwoMenuShortcut
objects are equal if theirkey
anduseShiftModifier
values are equal. - protected String paramString ()
- The
paramString()
method ofMenuShortcut
helps build up a string describing the shortcut; it appends the shortcut key and a shift modifier indicator to the string under construction. Oddly, this method is not currently used, nor can you call it;MenuShortcut
has its owntoString()
method that does the job itself. - public String toString()
- The
toString()
method ofMenuShortcut
builds aString
to display the contents of theMenuShortcut
.