-
Bug
-
Resolution: Fixed
-
P3
-
8u20, 9
-
b40
-
x86_64
-
windows_7
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8084210 | emb-9 | Alexandr Scherbatiy | P3 | Resolved | Fixed | team |
JDK-8065478 | 8u45 | Alexandr Scherbatiy | P3 | Resolved | Fixed | b01 |
JDK-8062897 | 8u40 | Alexandr Scherbatiy | P3 | Resolved | Fixed | b15 |
JDK-8070030 | emb-8u47 | Alexandr Scherbatiy | P3 | Resolved | Fixed | team |
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
(Small source code test case included)
In jdk7 and earlier the JComboBox actionListener provided an event where event.getActionCommand was equal to "comboBoxEdited". In jdk8 it does not.
The bug appears because of a source code change in JComboBox in jdk 8. In
javax.swing.JComboBox.java::actionPerformed the following two lines of code
were added in jdk8.
ComboBoxEditor editor = getEditor();
if ((editor != null) && (e != null) && (editor == e.getSource())) {
This test fails in jdk8 because
editor --> BasicComboBoxEditor
e.getSource --> BasicComboBoxEditor$BorderlessTextField
and so the event does not get delivered.
-------
Perhaps these lines were added because someone encountered multiple actionListener events for one edit. And instead of using getActionCommand() to filter the events they made this change and broke things.
REGRESSION. Last worked in version 7u67
ADDITIONAL REGRESSION INFORMATION:
all version 7 work correctly
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) compile attached source code
2) execute program, a JFrame with JComboBox is displayed
3) in click in combo, input some chars, for example "three", enter RETURN
4) there is no output, it should print the event
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The combo box listener should get an event where
"comboBoxEdited".equals(e.getActionCommand())
is true
ACTUAL -
no output
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package comboboxeditoreventbug;
import java.awt.EventQueue;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class ComboBoxEditorEventBug {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
EventQueue.invokeLater(() -> {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JComboBox combo = new JComboBox(new String[] {"one", "two"});
combo.setEditable(true);
combo.addActionListener((e) -> {
if("comboBoxEdited".equals(e.getActionCommand()))
System.out.println("action: " + e);
});
frame.add(combo);
frame.pack();
frame.setVisible(true);
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I do
combo.setEditor(new MyComboBoxEditor());
where
MyComboBoxEditor extends BasicComboBoxEditor
to provide MyTextField (which extends JTextField).
MyTextField overrides actionPerformed to provide it's associated combobox as
event.getSource instead of the text field itself.
I believe the correct fix is to remove the lines that were added in jdk8.
- backported by
-
JDK-8062897 JComboBox actionListener never receives "comboBoxEdited" from getActionCommand
-
- Resolved
-
-
JDK-8065478 JComboBox actionListener never receives "comboBoxEdited" from getActionCommand
-
- Resolved
-
-
JDK-8070030 JComboBox actionListener never receives "comboBoxEdited" from getActionCommand
-
- Resolved
-
-
JDK-8084210 JComboBox actionListener never receives "comboBoxEdited" from getActionCommand
-
- Resolved
-
- relates to
-
JDK-8019180 Use JComboBox as it's own ActionListener leads to unexpected behaviour
-
- Resolved
-
-
JDK-8072767 DefaultCellEditor for comboBox creates ActionEvent with wrong source object
-
- Resolved
-
-
JDK-8066142 closed/javax/swing/JComboBox/4212498/bug4212498.java:Edit the value in the text field and then press the tab key, the number don't increase
-
- Resolved
-