Duplicate :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : java version "1.5.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64) Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows 2000 [Version 5.00.2195] A DESCRIPTION OF THE PROBLEM : In versions prior to 5.0, JMenuItem(String,int) accepted a lower-case char for the second parameter and processed it the same as an upper-case. In Java 5 lower-case mnemonics appear to be ignored. But JMenuItem.setMnemonic(char) still accepts lower-case with no problem. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile and run the code below. Type alt-P. As expected, the "Problem" menu drops down. Press the hot key for the first menu item. Then go through the same cycle for the remaining menu items. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Expected each menu item's action listener to fire when its mnemonic is pressed. ACTUAL - Mnemonics set with setMnemonic, with a constructor taking a key event code, or with a constructor taking an upper-case letter, all worked. Mnemonics set with a constructor taking a lower-case letter did not work. Note that calling the constructor with a lower-case letter still managed to highlight that letter in the menu item text, so something recognized that this was a valid mnemonic, but it doesn't fire when the key is pressed. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.util.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Dork extends JFrame implements ActionListener { public static void main(String[] args) { Dork dork=new Dork(); dork.setVisible(true); } public Dork() { super("Dork"); setDefaultCloseOperation(EXIT_ON_CLOSE); JMenuBar bar=new JMenuBar(); setJMenuBar(bar); JMenu menu; JMenuItem item; menu=new JMenu("Good"); menu.setMnemonic('g'); bar.add(menu); item=new JMenuItem("Charity"); item.setMnemonic('c'); item.addActionListener(this); menu.add(item); item=new JMenuItem("Java"); item.setMnemonic('j'); item.addActionListener(this); menu.add(item); menu=new JMenu("Problem"); menu.setMnemonic('p'); bar.add(menu); item=new JMenuItem("setMnemonic(char)"); item.setMnemonic('s'); item.addActionListener(this); menu.add(item); item=new JMenuItem("Constructor(String,KeyEvent)",KeyEvent.VK_K); item.addActionListener(this); menu.add(item); item=new JMenuItem("Constructor(String,lc)",'l'); item.addActionListener(this); menu.add(item); item=new JMenuItem("Constructor(String,UC)",'U'); item.addActionListener(this); menu.add(item); pack(); setLocationRelativeTo(null); } public void actionPerformed(ActionEvent e) { JMenuItem source=(JMenuItem)e.getSource(); JOptionPane.showMessageDialog(this,source.getText()); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Change the mnemonic to upper-case or a virtual key code, or use setMnemonic. It's easy enough to work around in principle. The catch is that we have tons of code written for 1.4.2 that used lower case for the mnemonic. Release Regression From : 1.4.2_05 The above release value was the last known release where this bug was known to work. Since then there has been a regression. ###@###.### 2005-04-04 11:43:40 GMT
|