Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: MenuShortcut [javadoc | source]
java.lang.Object
   java.awt.MenuShortcut

All Implemented Interfaces:
    java$io$Serializable

The MenuShortcutclass 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('\u0444'), 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#getMenuShortcutKeyMask .

Field Summary
 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. 
 boolean usesShift    Indicates whether the shft key was pressed. If true, the shift key was pressed. If false, the shift key was not pressed 
Constructor:
 public MenuShortcut(int key) 
 public MenuShortcut(int key,
    boolean useShiftModifier) 
Method from java.awt.MenuShortcut Summary:
equals,   equals,   getKey,   hashCode,   paramString,   toString,   usesShiftModifier
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.MenuShortcut Detail:
 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.
 public boolean equals(Object obj) 
    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 getKey() 
    Returns the raw keycode of this MenuShortcut.
 public int hashCode() 
    Returns the hashcode for this MenuShortcut.
 protected String paramString() 
    Returns the parameter string representing the state of this MenuShortcut. This string is useful for debugging.
 public String toString() 
    Returns an internationalized description of the MenuShortcut.
 public boolean usesShiftModifier() 
    Returns whether this MenuShortcut must be invoked using the SHIFT key.