JDK-7172652 : With JDK 1.7 text field does not obtain focus when using mnemonic Alt/Key combin
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-05-30
  • Updated: 2018-03-21
  • Resolved: 2015-05-19
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 8 JDK 9 Other
8u121Fixed 9 b68Fixed openjdk7uFixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
If a Label control is configured with a mnemonic, the Alt/Key combination does not move focus to the text field configured in the "labelFor" property.
Instead the focus goes to  the first menu.

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Run the attached sample code.
2) Click on  the ���First name��� text field.
3) Press Alt/L to move the focus to the ���Last name��� text field.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Focus should move to ���Last name��� text field instead of moving to menu ���FirstMenu���.

ACTUAL -
Focus is not moved to ���Last name��� text field. Instead the focus is moved to menu ���FirstMenu���.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package com.samples;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class Sample extends JDesktopPane{
	
	JLabel firstLbl = new JLabel("First name");
	JLabel lastLbl = new JLabel("Last name");
	JMenuBar menuBar = new JMenuBar();
	
	JTextField firstTxtFld = new JTextField(20);
	JTextField lastTxtFld = new JTextField(20);
	
	public Sample() {
		
		boolean resizable = true;
		boolean closeable = true;
		boolean maximizable  = true;
		boolean iconifiable = true;
		String title = "Frame Title";
		JInternalFrame iframe = new JInternalFrame(title, resizable, closeable, maximizable, iconifiable);

		// Set an initial size
		int width = 200;
		int height = 50;
		iframe.setSize(width, height);

		// By default, internal frames are not visible; make it visible
		iframe.setVisible(true);
		
		JPanel pane = new JPanel();
		pane.setLayout(new FlowLayout());
		
		pane.add(firstLbl);
		pane.add(firstTxtFld);
		pane.add(lastLbl);
		pane.add(lastTxtFld);

		firstLbl.setLabelFor(firstTxtFld);
		firstLbl.setDisplayedMnemonic('F');
		
		lastLbl.setLabelFor(lastTxtFld);
		lastLbl.setDisplayedMnemonic('L');
		
		iframe.getContentPane().add(pane);
		iframe.setJMenuBar(menuBar);
		JMenu m = new JMenu("FirstMenu");
		//m.setMnemonic('i');
		menuBar.add(m);
		this.add(iframe);
	}
	
	public static void main(String[] args) throws Exception {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		JFrame frame = new JFrame();
		frame.getContentPane().add(new Sample (), BorderLayout.CENTER);
		frame.setSize(300, 300);
		frame.setVisible(true);
	}

}

---------- END SOURCE ----------

Comments
This is a bug in Label UI's key release event processing routine for key mnemonics: only one release event is captured instead of two (Alt release and the mnemonic key release). The Alt release event goes up on hierarchy and is captured by the internal frame menu for which Alt release means selection change event.
20-04-2015

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

You have approval to defer the following issues. Please update. Cheers, B.
07-10-2013

jdk8: SQE OK to defer
02-10-2013

8-defer-request: this is an issue from 7 GA, not a regression
02-10-2013

isn't a regression from jdk8 pov
02-10-2013