JDK-8019180 : Use JComboBox as it's own ActionListener leads to unexpected behaviour
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • Submitted: 2013-06-26
  • Updated: 2015-02-17
  • Resolved: 2014-05-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b22Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
1.7.0_06

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 6.1.7601

A DESCRIPTION OF THE PROBLEM :
If you use a JComboBox as it's own ActionListener you will get unexpected behaviour:

The entries become (visually) unselectable.

This problem encounters especially when inheriting a class from JComboBox that implements an ActionListener

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create a (not-empty) JComboBox
2. use it as it's own ActionListener
3. add it to a Window/Dialog/Frame/Panel and run it
4. select an entry, different from the first one

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An entry should get selected
ACTUAL -
No entry is selected

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public static void main(String[] args) {

JDialog dialog = new JDialog();

String[] entries = { " Cats " ,  " Porn " ,  " Lazors " ,  " Memes " };

// here starts the relevant part
JComboBox<String> myComboBox = new JComboBox<String>(entries);
myComboBox.addActionListener(myComboBox);
// here ends the relevant part

dialog.add(myComboBox);
dialog.pack();
dialog.setVisible(true);

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
If you need to inherit a class from JComboBox and you want to have it's own Listener, don't use ActionListener, use ItemListener instead.
Comments
http://cr.openjdk.java.net/~malenkov/8019180.9.0/
23-05-2014

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

Converted "8-client-defer-candidate" label to "8-defer-request" by SQE' OK.
15-08-2013

*This is anti-deferral criteria list*: - P2 -------------- Engineering's Criteria ------------------------------------- - tck-red labeled - conformance labeled - P3 regressions reported/labeled against jdk8 - findbugs, parfait, eht labeled bugs - CAP <1 year reported - netbeans <1 year reported Victor ----------------- SQE's OK --------------------------------- Yes, we are ok with that thanks, Mikhail
15-08-2013