JDK-6202699 : JComboBox editor locks up when calling selectAll() in focusGained()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-12-01
  • Updated: 2011-01-19
  • Resolved: 2005-04-15
Related Reports
Duplicate :  
Description
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 :
Linux darkstar 2.6.5-7.111-smp #1 SMP Wed Oct 13 15:45:13 UTC 2004 i686 i686 i386 GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
SUSE9.1 / KDE3.2.1

A DESCRIPTION OF THE PROBLEM :
When calling comboBox.getEditor().selectAll() in the focusGained() method of the JComboBox's FocusListener, the editor of the JComboBox locks up and no characters can be entered in the JComboBox via the keyboard.

Note that this used to works with JDK1.4.2.

Note that this works under Windows with JDK 1.4.2 and with JDK 1.5.0.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Start the program provided below, a frame will pop up showing the selected text "Apple".
2. Type the character "g".

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The text "Apple" in the JComboBox is replaced by the text "g".
ACTUAL -
The JComboBox persists to show the text "Apple". The character "g" is ignored.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
There is no error message shown when the error occurs.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFrame;

public class ComboBoxTest {

	public static void main(String[] args) {
		JFrame frame = new JFrame("ComboBox Test");
		final JComboBox comboBox = new JComboBox();
		comboBox.setModel(new DefaultComboBoxModel(new String[] { "Apple", "Orange", "Banana" }));
		comboBox.setEditable(true);
		comboBox.getEditor().getEditorComponent().addFocusListener(new FocusAdapter() {
			public void focusGained(FocusEvent e) {
				comboBox.getEditor().selectAll();
			}
		});
		frame.getContentPane().add(comboBox);
		frame.setVisible(true);
	}
}

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

CUSTOMER SUBMITTED WORKAROUND :
Replace the method focusGained() given in the example source code above by this version:

public void focusGained(FocusEvent e) {
	Component editor = comboBox.getEditor().getEditorComponent();
	if (editor instanceof JTextComponent) {
		((JTextComponent) editor).selectAll();
	}
}


Comments
EVALUATION This sounds like an AWT problem. I can't reproduce it on Windows NT 4. Note: I had to modify the test case slightly to give the frame a size since it was coming up 0, 0. ###@###.### 2004-12-02 15:56:56 GMT This looks like a duplicate of 5082319 "REGRESSION: JComboBox don't respond to arrow keys on linux (has focus listener)". The problem seems to be the same. Also, this bug is not reproducible since Mustang-b10 most likely because of the fix for 5082319 that was intergrated just into b10. So, I'm closing this duplicate. ###@###.### 2005-04-15 09:01:54 GMT
02-12-2004