-
Bug
-
Resolution: Fixed
-
P3
-
1.4.2, 5.0
-
beta
-
x86
-
windows_2000, windows_xp
Name: ks84122 Date: 01/28/2003
Modify selected item in editable JComboBox in a JFrame with a default button. Pressing Enter once does nothing visible, pressing Enter a second time fires the default button.
(The scenario as I see it follows. BasicComboBoxUI sees modified value does not match selected item so does not fire "enterpressed". JComboBox does not distinguish between popup visible or not in behavior so just fires "comboBoxEdited" which changes the selection. On next Enter, selected item does match visible value so now does fire "enterpressed".)
Run sample code below. If hit Enter without modifying content of JComboBox, Enter closes the dialog by firing the default button. If modify content, have to hit Enter twice to close the dialog.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Frame1 extends JFrame {
JButton jButton1 = new JButton();
JComboBox jComboBox1 = new JComboBox(new String[] {"one", "two"});
public Frame1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jComboBox1.setEditable(true);
jButton1.setText("OK");
jButton1.setDefaultCapable(true);
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
getContentPane().add(jButton1, BorderLayout.SOUTH);
getContentPane().add(jComboBox1, BorderLayout.NORTH);
getRootPane().setDefaultButton(jButton1);
}
void jButton1_actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
}
class Frame1_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
public static void main(String[] args) {
Frame1 frame = new Frame1();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setLocation(new Point(200, 200));
frame.show();
}
}
(Review ID: 180316)
======================================================================
- duplicates
-
JDK-6199690 Combobox editor prevents default button from working after keys are typed
-
- Closed
-
- relates to
-
JDK-5109875 REGRESSION : ENTER on editable JComboBox goes to Default Button.
-
- Closed
-