JDK-6396785 : REGRESSION: A component can get unexpected keyTyped event.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_10,windows_xp
  • CPU: x86,sparc
  • Submitted: 2006-03-10
  • Updated: 2011-01-19
  • Resolved: 2006-07-21
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 b93Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
If you open a dialog using a spacebar for the menu item, the space character will get written into a focused text component inside the dialog.

Step to reproduce:
---------------------
1) Run the attached program. You will see a Frame with File Menu . 
2) Press ALT + F . You see a MenuItem 'Test'.
3) Press spacebar to select the 'Test' MenuItem. An ActionEvent triggers & you will see a 
   dialog with textfield. Make the dialog larger. you will see a space character in the 
   textfield. 

I tested this with win xp & solaris 10 with PIT build 77.

Comments
SUGGESTED FIX Find the webrev here: http://javaweb.sfbay/jcg/1.6.0-mustang/awt/6396785
11-07-2006

EVALUATION To fix this problem it has been decided to roll back the following changes: 1. Fix to 5028014; 2. A part of fix to 5064013: it concerns the changing condition of comparing times of a marker and a key event (see the CR). 3. Change in BasicPopupMenuUI.java (see the suggested fix to 6391688). This change is rolled back just as unnecessary. Summarizing, this rollback will resolve: 1. This CR 6396785; 2. ButtonTest.java issue. Reported in this CR by ###@###.### (see the evaluation); 3. CR 6346690 (6363026 in mustang-rc); 4. CR 6380743; 5. CR 6391688.
22-06-2006

EVALUATION I found out that the problem is more serious: it involves all swing components. When you bind a key for an action in the component input map, calls the action by pressing the key and during the action focus transfers to other component, it gets the keyTyped event. There is small test case: --- Source begin --- import java.awt.BorderLayout; import java.awt.event.ActionEvent; import javax.swing.*; public class ButtonTest { public static void main(String args[]) { final JButton btn = new JButton("Press the A key"); btn.getInputMap().put(KeyStroke.getKeyStroke("A"), "GO!"); btn.getActionMap().put("GO!", new AbstractAction() { public void actionPerformed(ActionEvent e) { System.out.println("Action performed!"); btn.transferFocus(); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(btn, BorderLayout.CENTER); f.getContentPane().add(new JTextField(), BorderLayout.SOUTH); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } } --- Source end --- Testing strategy: 1. Run the test 2. Press the 'a' key 3. See that 'a' is typed in the text field
09-06-2006

EVALUATION I think the bug is tightly related to 6346690. Copied from 6346690: It worked perfectly in b57, gets broken in b58. It seems that the fix for 5028014 changed the timing and the sequence of events, which resulted in this regression.
19-04-2006

EVALUATION I not found the bug in 1.5_06 and current 1.5_08. I found it in 1.6 b65. It is a regression.
19-04-2006

EVALUATION Fixing type ahead implementation is a possible way of fixing all related problems for Swing reassigned to AWT
24-03-2006

EVALUATION AWT has provided some API to consume next KEY_TYPED event that is used in mnemonic key event handlers. I suppose that activating a menu item with a space is handled in some special way and it also should be taken into acount. For details please see the related problems: 6391688, 6363026, 6346690. Reassigning to Swing.
10-03-2006