The Swing Applicatioun Framework (JSR-296) supports initializing the
mnemonic properties of labels and buttons and actions from strings
that contain a marker, like "Save &As". Presently, there's no
supported way to determine if the current keyboard has a key that
matches the marked character. There are some hacks in the existing
Swing implementation that deal with this:
AbstractButton#setMnemonic(char) just uppercases it's char if it's
between 'a' and 'z' and then uses the ascii code. This method is
JLabel has the very same hack and it's setMnemonic(char) method is not
Using a marker character to identify a mnemonic in a text string is a
common (and beloved!) simplification vs specifying a mnemonic keycode
and "displayed mnemonic index" explicitly. We need a way to do this
that works correctly in general.
AWTKeyStroke.getAWTKeyStroke(char).getKeyCode() always returns 0
because it returns a KEY_TYPED event and because apparently KEY_TYPED
events are supposed to have 0 for a keycode. I have no idea why (the
javadoc was not illuminating).
The NetBeans implementation, see Mnemonics#getLatinKeycode in
handles this by looking up an additional resource that maps a char to
a VK_ keycode. This makes it possible to deal with arbitrary
characters in a marked mnemonic string but is an unneccessary burden
for the developer.