JDK-6391688 : Mnemonics typed into text field in dialog
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P1
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux_redhat_9.0,windows_xp
  • CPU: x86
  • Submitted: 2006-02-28
  • Updated: 2011-01-22
  • Resolved: 2006-03-20
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 6
6 b77Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
If you open a dialog using a mnemonic for the menu item, the mnemonic will get written into a focused text component inside the dialog. I have attached a test case, just unzip it, build using ant and run. Try Alt+f g, it will popup a dialog and 'g' will be inserted into its text field. The app will also print call stack of the text field modification.

Comments
SUGGESTED FIX ------- BasicPopupMenuUI.java ------- *** /tmp/sccs.OuaaoN Wed Mar 1 15:08:38 2006 --- BasicPopupMenuUI.java Wed Mar 1 13:41:07 2006 *************** *** 327,339 **** if (item instanceof JMenu) { // submenus are handled in menuKeyTyped menuToOpen = item; } else if (item.isEnabled()) { // we have a menu item manager.clearSelectedPath(); item.doClick(); - sun.awt.SunToolkit.consumeNextKeyTyped(e); } e.consume(); } else { // Select the menu item with the matching mnemonic. If // the same mnemonic has been invoked then select the next --- 327,339 ---- if (item instanceof JMenu) { // submenus are handled in menuKeyTyped menuToOpen = item; } else if (item.isEnabled()) { // we have a menu item + sun.awt.SunToolkit.consumeNextKeyTyped(e); manager.clearSelectedPath(); item.doClick(); } e.consume(); } else { // Select the menu item with the matching mnemonic. If // the same mnemonic has been invoked then select the next
02-03-2006

EVALUATION The problem is as follows. Below is some part of the code that handles mnemonic key events: 322 if (matches == 0) { 323 ; // no op 324 } else if (matches == 1) { 325 // Invoke the menu action 326 JMenuItem item = (JMenuItem)items[firstMatch]; 327 if (item instanceof JMenu) { 328 // submenus are handled in menuKeyTyped 329 menuToOpen = item; 330 } else if (item.isEnabled()) { 331 // we have a menu item 332 manager.clearSelectedPath(); 333 item.doClick(); 334 sun.awt.SunToolkit.consumeNextKeyTyped(e); 335 } 336 e.consume(); 337 } else { 338 // Select the menu item with the matching mnemonic. If Look into the line 333. This method triggers the dialog from the testcase to be shown. As the dialog is modal, it start new event pump in new thread. Thus here a switch between threads happens. And the following line 334 will be executed only after the dialog is closed. But this line is exactly what fixes the problem with mnemonics (See 6363026, 6380743). The solution is to move this call up to the beggining of the else-if-statement.
01-03-2006

EVALUATION Here is a simplified (for AWT) testcase: import java.awt.Dialog; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JTextField; import javax.swing.WindowConstants; public class simplified_test { public static void main(String args[]) { JMenuItem testItem = new JMenuItem(); testItem.setMnemonic('s'); testItem.setText("Test"); testItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JDialog d = new JDialog((Window)null, "", Dialog.ModalityType.DOCUMENT_MODAL); d.add(new JTextField()); d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); d.pack(); d.setVisible(true); } }); JMenu menu = new JMenu(); menu.setMnemonic('f'); menu.setText("File"); menu.add(testItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); JFrame f = new JFrame("mnemonics"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); f.setJMenuBar(menuBar); f.pack(); f.setVisible(true); } }
28-02-2006