JDK-6403983 : REGRESSION: MenuItem Mnemonic KeyEvent passed to JDialog Textfield
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-03-24
  • Updated: 2011-01-26
  • Resolved: 2006-03-28
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REGRESSION :
A JFrame has a JMenuItem (e.g. 'Project') under a JMenu (e.g. 'File').  The menu item has a mnemonic (e.g. 'p').  Upon selection, the menu item opens a JDialog containing a JTextfield.

When selecting the JMenuItem via the mnemonic, the Key_Pressed KeyEvent is consumed but subsequent Key_Typed and Key_Released KeyEvents are passed to the dialog's textfield, i.e. a 'p' appears in the textfield.

REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
When the following code is running, if you type "Alt-f", then "p", the dialog pops up with a 'p' in the textfield. If you click through the menu or change the JDialog to a JFrame, it acts fine (i.e. the textfield is empty).

Sample Program:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
 
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
 
public class DemoCode extends JDialog {
	
	public DemoCode(JFrame owner) {
		super(owner,true);
		this.add(new JTextField(15));
		this.pack();
		this.setVisible(true);
	}
 
	public static void main(String[] args) {
		final JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JMenuBar menuBar = new JMenuBar();
		JMenu fileMenu = new JMenu("File");
		fileMenu.setMnemonic(KeyEvent.VK_F);
		JMenuItem projectMenuItem = new JMenuItem("Project", KeyEvent.VK_P);
		
		projectMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				new DemoCode(frame);
			}
		});
		
		fileMenu.add(projectMenuItem);
		menuBar.add(fileMenu);
		frame.setJMenuBar(menuBar);
		
		frame.pack();
		frame.setVisible(true);
	}
}

RELEASE LAST WORKED:
5.0 Update 6

RELEASE TEST FAILS:
mustang-b72

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
When selecting the menuitem through the mnemonic, the JDialog should pop up with an empty textfield.
ACTUAL -
Instead, selecting the menuitem through the mnemonic pops up the JDialog with the mnemonic entered in the textfield.

Comments
EVALUATION It's a duplicate of 6391688 "Mnemonics typed into text field in dialog" fixed only in b77.
28-03-2006

EVALUATION I believe this is a duplicate of an AWT bug.
27-03-2006