-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.0.1
-
None
-
sparc
-
solaris_2.5.1
I created an editable combox-box and attached an ActionListener
to it. I ran the program, entered some text and hit the Return
key. My ActionListener was invoked. Then, without changing the
text in the combo-box, I hit Return again expecting that my ActionListener
would be invoked again, but it wasn't. I discovered that the ActionListener
was only getting invoked when Return had been hit and the text had changed
since the last time the ActionListener had been invoked.
My real world scenario was an attempt to use a combo-box for a Find field
where I wanted to remember the previous find strings in the drop-down list.
I want the user to be able to hit Return to do the first find and to
subsequently hit Return to do repeated finds of the same string.
Here is a small program that demonstrates the problem. Run the program,
type into the combo-box and then hit Return several times. Notice that
you get just one line of output rather than a line per Return.
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.sun.java.swing.JFrame;
import com.sun.java.swing.JComboBox;
import com.sun.java.swing.JFrame;
public class ComboBoxBug1 {
/**
* Constructor.
*/
public ComboBoxBug1 () {
}
public static void main(String args[]) {
JFrame frame = new JFrame("ComboBox Bug");
Container contentPane = frame.getContentPane();
JComboBox comboBox = new JComboBox();
comboBox.setEditable(true);
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.err.println("actionPerformed invoked");
}
});
contentPane.setLayout(new FlowLayout());
contentPane.add(comboBox);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
to it. I ran the program, entered some text and hit the Return
key. My ActionListener was invoked. Then, without changing the
text in the combo-box, I hit Return again expecting that my ActionListener
would be invoked again, but it wasn't. I discovered that the ActionListener
was only getting invoked when Return had been hit and the text had changed
since the last time the ActionListener had been invoked.
My real world scenario was an attempt to use a combo-box for a Find field
where I wanted to remember the previous find strings in the drop-down list.
I want the user to be able to hit Return to do the first find and to
subsequently hit Return to do repeated finds of the same string.
Here is a small program that demonstrates the problem. Run the program,
type into the combo-box and then hit Return several times. Notice that
you get just one line of output rather than a line per Return.
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.sun.java.swing.JFrame;
import com.sun.java.swing.JComboBox;
import com.sun.java.swing.JFrame;
public class ComboBoxBug1 {
/**
* Constructor.
*/
public ComboBoxBug1 () {
}
public static void main(String args[]) {
JFrame frame = new JFrame("ComboBox Bug");
Container contentPane = frame.getContentPane();
JComboBox comboBox = new JComboBox();
comboBox.setEditable(true);
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.err.println("actionPerformed invoked");
}
});
contentPane.setLayout(new FlowLayout());
contentPane.add(comboBox);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
- relates to
-
JDK-4145135 JComboBox editor component fires an ActionEvent when focus is lost
-
- Closed
-
-
JDK-4147476 JComboBox does not fire actionPerformed() on every ENTER key
-
- Closed
-