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();
}
}