JDK-6246463 : JComboBox triggers ActionEvent which clicking inside the empty drop-down
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-03-26
  • Updated: 2014-05-14
  • Resolved: 2005-08-31
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 6
6 b50Fixed
Related Reports
Relates :  
Relates :  
Description
I am adding an empty JComboBox to a JFrame. When I click on it, an empty popup is shown. When I click inside the empty popup, I am getting an action event. This is incorrect. An empty JComboBox shoud not trigger any action event. This happens only when I use the mouse. No action event is triggered when using keyboard and pressing the down arrow. 

This is reproducible atleast since 1.4. 

I have attached a sample test. Execute the sample test. Click on the combo box. You would see an empty drop-down. Click inside the empty drop-down. You would get an action event in the console.

I thought this is same as the bug 4760078 but this bug deals with spurious actionevents triggered during focus lost. So I am filing this one separately.
###@###.### 2005-03-26 14:24:31 GMT

###@###.### 2005-07-04 18:56:45 GMT

Comments
SUGGESTED FIX *** --- BasicComboPopup.java Fri May 13 21:00:28 2005 *************** *** 808,815 **** public void mouseReleased(MouseEvent e) { if (e.getSource() == list) { ! // JList mouse listener ! comboBox.setSelectedIndex( list.getSelectedIndex() ); comboBox.setPopupVisible(false); // workaround for cancelling an edited item (bug 4530953) if (comboBox.isEditable() && comboBox.getEditor() != null) { --- 808,817 ---- public void mouseReleased(MouseEvent e) { if (e.getSource() == list) { ! if (list.getModel().getSize() > 0) { ! // JList mouse listener ! comboBox.setSelectedIndex( list.getSelectedIndex() ); ! } comboBox.setPopupVisible(false); // workaround for cancelling an edited item (bug 4530953) if (comboBox.isEditable() && comboBox.getEditor() != null) {
19-08-2005

EVALUATION It was decided to modify BasicComboPopup.Handler.mouseReleased() method to fix this bug.
19-08-2005

EVALUATION I think, in JComboBox.setSelectedIndex() in case the parameter is -1 we should check if the combo box popup is empty. In this case, we shouldn't do anything. ###@###.### 2005-07-04 18:58:15 GMT
04-07-2005