JDK-6559449 : Support for converting from char to KeyEvent VK_ keycode
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-05-18
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b55Fixed
Related Reports
Relates :  
Description
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
deprecated.

JLabel has the very same hack and it's setMnemonic(char) method is not
deprecated.  

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
http://www.netbeans.org/source/browse/openide/awt/src/org/openide/awt/
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.

Comments
EVALUATION [SQE] To test new API, please use a manual test from 6680988. Beware, to use it, you must have Russian keyboard layout available. The new API is especially useful for Unicode characters having no VK_ codes. [/SQE]
27-04-2009

EVALUATION Life made easier with the new methods introduced in the fix to 6680988, see the corresp. test there.
27-03-2009