-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
1.0.2
-
None
-
sparc
-
solaris_2.5.1
I originally filed this as bug 4145134 and I am now re-filing
the problem as an RFE. The original evaluation explained that the
current semantics are intended (it did not explain why). I'm guessing
that the motivation is that many uses of the combo box are only concerned
with changes. If someone hits return several times on a combo box
that controls a font size, you only need to change the font size once.
This is sensible and seems like the proper default.
My RFE here is for a property that controls this behaviour. I would like
to see a property that can be set such that each Return in an editable
combo box fires an ActionEvent. The workaround requires me to know
too much about the implementation of the combo box. Can I really be
sure that the Editor is a JTextField? To do it correctly, I should
implement my own editor so I know what kind of control it is. This
is requiring far too much just so I can get and ActionEvent on each
Return.
The original description:
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);
}
}
the problem as an RFE. The original evaluation explained that the
current semantics are intended (it did not explain why). I'm guessing
that the motivation is that many uses of the combo box are only concerned
with changes. If someone hits return several times on a combo box
that controls a font size, you only need to change the font size once.
This is sensible and seems like the proper default.
My RFE here is for a property that controls this behaviour. I would like
to see a property that can be set such that each Return in an editable
combo box fires an ActionEvent. The workaround requires me to know
too much about the implementation of the combo box. Can I really be
sure that the Editor is a JTextField? To do it correctly, I should
implement my own editor so I know what kind of control it is. This
is requiring far too much just so I can get and ActionEvent on each
Return.
The original description:
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);
}
}
- relates to
-
JDK-4145134 JComboBox does not fire actionPerformed() on every ENTER key
-
- Closed
-