public class Mnemonic extends Object
getMnemonic(String)
.Modifier and Type | Field and Description |
---|---|
int |
index
The index to use as an argument to
AbstractButton.setDisplayedMnemonicIndex(int) . |
int |
keycode
The keycode to use as an argument to
AbstractButton.setMnemonic(int) . |
String |
text
The unencoded text.
|
Modifier and Type | Method and Description |
---|---|
static Mnemonic |
getMnemonic(String input)
Create a Mnemonic instance with the mnemonic information from the
given encoded String.
|
static void |
setDisplayedMnemonicIndex(Component c,
int index)
Set the displayed mnemonic index, if doing so is supported.
|
void |
setMnemonic(AbstractButton button)
Apply this mnemonic to the given AbstractButton.
|
void |
setMnemonic(Action action)
Apply this mnemonic to the given Action.
|
void |
setMnemonic(JLabel label)
Apply this mnemonic to the given JLabel.
|
void |
setMnemonic(JTabbedPane tabbedPane,
int tabIndex)
Apply this mnemonic to the given JLabel.
|
String |
toString() |
static boolean |
useMnemonics() |
public String text
public int keycode
AbstractButton.setMnemonic(int)
. Returns
KeyEvent.VK_UNDEFINED if no mnemonic was found.public int index
AbstractButton.setDisplayedMnemonicIndex(int)
. Returns
-1 if the default value should be used.public static void setDisplayedMnemonicIndex(Component c, int index)
public void setMnemonic(AbstractButton button)
public void setMnemonic(JLabel label)
public void setMnemonic(JTabbedPane tabbedPane, int tabIndex)
public void setMnemonic(Action action)
public static Mnemonic getMnemonic(String input)
Mnemonics may be encoded as follows:
Original Text | Visible Text | Mnemonic |
&File | File | VK_F |
Save &As... | Save As... | VK_A second instance |
Me&&&You | Me&You | VK_Y ambiguous ampersands must be escaped |
Sugar & Spice | Sugar & Spice | None ampersand is unambiguous, whitespace is not allowed as a mnemonic |
Swing restricts mnemonics to available KeyEvent VK_ constants, so there must exist a mapping between text characters and said constants. If the obvious mappings (A-Z, a-z, 0-9) don't hold, lookup falls back to other methods. Whitespace, quotes, and ampersand are disallowed as mnemonics.
Mappings from arbitrary characters to mnemonic keys may be defined
by providing a property
MNEMONIC_{unicode char}={KeyEvent.VK_ constant name} within a bundle
accessible by abbot.i18n.Strings
. If no such
mapping is defined, a VK_ code is guessed by checking if there can be
found a keystroke mapping for the original character.
KeyStrokeMap
,
Strings
public static boolean useMnemonics()
Abbot is hosted on