MenuShortcut class represents a keyboard accelerator
for a MenuItem.
Menu shortcuts are created using virtual keycodes, not characters. For example, a menu shortcut for Ctrl-a (assuming that Control is the accelerator key) would be created with code like the following:
MenuShortcut ms = new MenuShortcut(KeyEvent.VK_A, false);
or alternatively
MenuShortcut ms = new MenuShortcut(KeyEvent.getExtendedKeyCodeForChar('A'), false);
Menu shortcuts may also be constructed for a wider set of keycodes
using the java.awt.event.KeyEvent.getExtendedKeyCodeForChar call.
For example, a menu shortcut for "Ctrl+cyrillic ef" is created by
MenuShortcut ms = new MenuShortcut(KeyEvent.getExtendedKeyCodeForChar('ф'), false);
Note that shortcuts created with a keycode or an extended keycode defined as a constant in KeyEvent
work regardless of the current keyboard layout. However, a shortcut made of
an extended keycode not listed in KeyEvent
only work if the current keyboard layout produces a corresponding letter.
The accelerator key is platform-dependent and may be obtained
via Toolkit#getMenuShortcutKeyMaskEx().
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | key
The virtual keycode for the menu shortcut. |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability. |
| pack-priv boolean | usesShift
Indicates whether the shift key was pressed. |
| Access | Constructor and Description |
|---|---|
| public | MenuShortcut(int
the raw keycode for this MenuShortcut, as would be returned
in the keyCode field of a key)KeyEvent if
this key were pressed.Constructs a new MenuShortcut for the specified virtual keycode. |
| public | MenuShortcut(int
the raw keycode for this MenuShortcut, as would be returned
in the keyCode field of a key, boolean KeyEvent if
this key were pressed.indicates whether this MenuShortcut is invoked
with the SHIFT key down. useShiftModifier)Constructs a new MenuShortcut for the specified virtual keycode. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if this MenuShortcut is the same as another,
false otherwise.the MenuShortcut to compare with this. s)Returns whether this MenuShortcut is the same as another: equality is defined to mean that both MenuShortcuts use the same key and both either use or don't use the SHIFT key. |
| public boolean | Returns: true if this MenuShortcut is the same as another,
false otherwise.the Object to compare with this. obj)Overrides java. Returns whether this MenuShortcut is the same as another: equality is defined to mean that both MenuShortcuts use the same key and both either use or don't use the SHIFT key. |
| public int | |
| public int | Returns: the hashcode for this MenuShortcut.Overrides java. Returns the hashcode for this MenuShortcut. |
| protected String | Returns: the parameter string of this MenuShortcut.Returns the parameter string representing the state of this MenuShortcut. |
| public String | Returns: a string representation of this MenuShortcut.Overrides java. Returns an internationalized description of the MenuShortcut. |
| public boolean | Returns: true if this MenuShortcut must be invoked using the
SHIFT key, false otherwise.Returns whether this MenuShortcut must be invoked using the SHIFT key. |
| key | back to summary |
|---|---|
| pack-priv int key The virtual keycode for the menu shortcut. This is the keycode with which the menu shortcut will be created. Note that it is a virtual keycode, not a character, e.g. KeyEvent.VK_A, not 'a'. Note in 1.1.x you must use setActionCommand() on a menu item in order for its shortcut to work, otherwise it will fire a null action command.
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.1 for interoperability. | |
| usesShift | back to summary |
|---|---|
| pack-priv boolean usesShift Indicates whether the shift key was pressed. If true, the shift key was pressed. If false, the shift key was not pressed
| |
| MenuShortcut | back to summary |
|---|---|
| public MenuShortcut(int key) Constructs a new MenuShortcut for the specified virtual keycode.
| |
| MenuShortcut | back to summary |
|---|---|
| public MenuShortcut(int key, boolean useShiftModifier) Constructs a new MenuShortcut for the specified virtual keycode.
| |
| equals | back to summary |
|---|---|
| public boolean equals(MenuShortcut s) Returns whether this MenuShortcut is the same as another: equality is defined to mean that both MenuShortcuts use the same key and both either use or don't use the SHIFT key.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Returns whether this MenuShortcut is the same as another: equality is defined to mean that both MenuShortcuts use the same key and both either use or don't use the SHIFT key.
| |
| getKey | back to summary |
|---|---|
| public int getKey() Returns the raw keycode of this MenuShortcut.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns the hashcode for this MenuShortcut.
| |
| paramString | back to summary |
|---|---|
| protected String paramString() Returns the parameter string representing the state of this MenuShortcut. This string is useful for debugging.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns an internationalized description of the MenuShortcut.
| |
| usesShiftModifier | back to summary |
|---|---|
| public boolean usesShiftModifier() Returns whether this MenuShortcut must be invoked using the SHIFT key.
| |