JDK-4838135 : Request javax.swing.Action.MNEMONIC_INDEX_KEY
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0,1.4.1_01
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux,linux_redhat_7.2
  • CPU: x86
  • Submitted: 2003-03-26
  • Updated: 2017-05-19
  • Resolved: 2003-07-22
Related Reports
Duplicate :  
Description
javax.swing.Action has a defined key used for storing a mnemonic to use with the action when presented as e.g. a menu item.

Unfortunately it does not permit you to set the displayed mnemonic index (which capability was added to Swing in 1.4). Consider an action "Save All" for which you would like the mnemonic 'A' at index 5. You would like it to display as "Save _A_ll" but it will actually display as "S_a_ve All" which is uglier.

There are also cases involving languages which do not use the Latin script that you need to explicit set the displayed index. For example, on a JMenuItem with the name rendered as Cyrillic "PHayl" (i.e. "File") you may wish to set a mnemonic using keystroke 'F' and place it at index 0 on the phi character. This is possible using JMenuItem directly, but not by creating an Action and calling JMenu.add(Action).
###@###.### 2003-03-26

Comments
EVALUATION This is a great idea. setDisplayedMnemonicIndex was added in 1.4 connecting this property to the Actions architecture would make this property accessible from the actions. Commit to 1.5 but may implement this under the blanket RFE 4491747: Use of Action still needs work. ###@###.### 2003-03-31 I've decided to add the MNEMONIC_INDEX_KEY and associated accessors in AbstractAction under RFE 4491747.
31-03-2003

WORK AROUND Avoid Action and directly create presenters such as JMenuItem. Or live with the misplaced or missing mnemonics. ###@###.### 2003-03-26
26-03-2003

SUGGESTED FIX Suggest adding a constant such as MNEMONIC_INDEX_KEY, optional of course, type int, corresponding to AbstractButton.displayedMnemonicIndex, and editing AbstractButton.configurePropertiesFromAction accordingly. NetBeans has already dealt with this issue: http://www.netbeans.org/source/browse/~checkout~/openide/src/org/openide/awt/Actions.java http://www.netbeans.org/source/browse/~checkout~/openide/src/org/openide/awt/Mnemonics.java If you create an action with an ampersand in the name before a letter, that letter is given a mnemonic, and it will be correctly placed if you are using JDK 1.4. Non-Latin scripts are supported in 1.4 as well, using a translation table mapping characters to keystrokes. Thus in NetBeans code it is discouraged to do this: Action a; JMenuItem mi = new JMenuItem(); mi.setAction(a); jPopupMenu.add(mi); you need to do this: Action a; JMenuItem mi = new JMenuItem(); Actions.connect(mi, a, true); jPopupMenu.add(mi); ###@###.### 2003-03-26
26-03-2003