APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt

public Class MenuShortcut

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.awt.event.InputEvent, .KeyEvent, java.io.Serial

The 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().

Author
Thomas Ball
Since
1.1

Field Summary

Modifier and TypeField 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.

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this MenuShortcut is the same as another, false otherwise.
equals
(MenuShortcut
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.
equals
(Object
the Object to compare with this.
obj
)

Overrides java.lang.Object.equals.

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

Returns:

the raw keycode of this MenuShortcut.
getKey
()

Returns the raw keycode of this MenuShortcut.

public int

Returns:

the hashcode for this MenuShortcut.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hashcode for this MenuShortcut.

protected String

Returns:

the parameter string of this MenuShortcut.
paramString
()

Returns the parameter string representing the state of this MenuShortcut.

public String

Returns:

a string representation of this MenuShortcut.
toString
()

Overrides java.lang.Object.toString.

Returns an internationalized description of the MenuShortcut.

public boolean

Returns:

true if this MenuShortcut must be invoked using the SHIFT key, false otherwise.
usesShiftModifier
()

Returns whether this MenuShortcut must be invoked using the SHIFT key.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

keyback 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.

Since
1.1
See Also
getKey(), usesShiftModifier(), java.awt.event.KeyEvent
serialVersionUIDback to summary
private static final long serialVersionUID

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial
usesShiftback 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

Since
1.1
See Also
usesShiftModifier()

Constructor Detail

Method Detail

equalsback 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.

Parameters
s:MenuShortcut

the MenuShortcut to compare with this.

Returns:boolean

true if this MenuShortcut is the same as another, false otherwise.

Since
1.1
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

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.

Parameters
obj:Object

the Object to compare with this.

Returns:boolean

true if this MenuShortcut is the same as another, false otherwise.

Since
1.2
getKeyback to summary
public int getKey()

Returns the raw keycode of this MenuShortcut.

Returns:int

the raw keycode of this MenuShortcut.

Since
1.1
See Also
java.awt.event.KeyEvent
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hashcode for this MenuShortcut.

Returns:int

the hashcode for this MenuShortcut.

Since
1.2
paramStringback to summary
protected String paramString()

Returns the parameter string representing the state of this MenuShortcut. This string is useful for debugging.

Returns:String

the parameter string of this MenuShortcut.

Since
1.1
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns an internationalized description of the MenuShortcut.

Returns:String

a string representation of this MenuShortcut.

Since
1.1
usesShiftModifierback to summary
public boolean usesShiftModifier()

Returns whether this MenuShortcut must be invoked using the SHIFT key.

Returns:boolean

true if this MenuShortcut must be invoked using the SHIFT key, false otherwise.

Since
1.1