JDK-6481184 : AbstractButton.setMnemonic(int mnemonic) is case-sensitive
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-10-12
  • Updated: 2011-02-16
  • Resolved: 2006-10-16
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft windows 2000 5.00.2195 Service pack 4

EXTRA RELEVANT SYSTEM CONFIGURATION :
no relevant information

A DESCRIPTION OF THE PROBLEM :
The javadoc tells us that the method AbstractButton.setMnemonic(int mnemonic) is case-insensitive, but that not true. It only works if the int reprecents a uppercase from A -> Z.
The method AbstractButton.setMnemonic(char mnemonic) works perfect for characters a->z en A-> Z, but this method is obsolete.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a menu with different menuItems. Define a mnemonic on a lowercase of the menuItem and try to activate the menuItem using his mnemonic.
This doesn't work if you use the method setMnemonic(int mnemonic) with the mnemonic as lower-case representation.
Use the method setMnemonic(char mnemonic) with the mnemonic as lower-case and it works perfectly.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This doesn't work if you use the method setMnemonic(int mnemonic) with the mnemonic as lower-case representation.
Use the method setMnemonic(char mnemonic) with the mnemonic as lower-case and it works perfectly.
ACTUAL -
This doesn't work if you use the method setMnemonic(int mnemonic) with the mnemonic as lower-case representation.
Use the method setMnemonic(char mnemonic) with the mnemonic as lower-case and it works perfectly.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No messages, just no activation of the menuitem

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Do a Charactor.uppercase(mnemonic) before doing the setMnemonic(int mnemonic).

Comments
EVALUATION The submitter isn't entirely correct. The JavaDoc says the following: * A mnemonic must correspond to a single key on the keyboard * and should be specified using one of the <code>VK_XXX</code> * keycodes defined in <code>java.awt.event.KeyEvent</code>. * Mnemonics are case-insensitive, therefore a key event * with the corresponding keycode would cause the button to be * activated whether or not the Shift modifier was pressed. In particular, the mnemonic given to setMnemonic(int) must be specified in terms of a VK_XXX key code, not a character. The case-insensitive aspect simply refers to the fact that a mnemonic can be activated regardless of whether or not Shift (or CAPS-LOCK) is held down. However, there is an aspect of this where they are correct. Due to buggy code, prior to 5.0, we allowed mnemonics to be specified with lowercase characters for menu items. We fixed this in 5.0, but users were relying on the old behavior. As such, the old behavior has been restored for JDK 6, under bug number 6249972.
16-10-2006