JDK-6607130 : REGRESSION: JComboBox cell editor isn't hidden if the same value is selected with keyboard
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-09-20
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
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 7
7 b38Fixed
Related Reports
Relates :  
Relates :  
Description
Platform: any
JDK: 6, 7

JComboBox cell editor isn't hidden if the same value is selected with keyboard. 
Steps to reproduce:
1. Execute the JComboBoxTest from the attachment.
2. Note that 'one' item is selected twice with the keyboard.
3. When it was selected at the second time, JComboBox editor stays visible, though it should be hidden.

Comments
SUGGESTED FIX The approved webrev revision was copied to NFS: /net/sa.sfbay/export/home/swing/data/7/6607130.2 URL: http://sa.sfbay.sun.com/projects/swing_data/7/6607130.2
21-07-2008

EVALUATION It is a regression of 6428549. The problem is in BasicComboBoxUI.Actions.actionPerformed() method in the code related to ENTER key: 1513 comboBox.getModel().setSelectedItem(listItem); If listItem is the same as the current selected object, this method doesn't fire an action event, which is necessary for combo box hiding. DefaultCellEditor.actionPerformed() method is responsible for hiding and it is not called. The solution is simple. We can use instead 1513 comboBox.setSelectedItem(listItem); It generates the necessary event. DefaultCellEditor.actionPerformed() is called. Editor hides. Moreover, we can remove the following lines without any negative effects: 1549 // Ensure that JComboBox.actionPerformed() 1550 // doesn't set editor value as selected item 1551 comboBox.getEditor().setItem(listItem); It is because the new line "comboBox.setSelectedItem(listItem);" indirectly sets the editor's value in the same way as the deleted line. Here is the stack trace of a comboBox.setSelectedItem() call: setItem():59, javax.swing.plaf.basic.BasicComboBoxEditor configureEditor():1383, javax.swing.JComboBox contentsChanged():1798, javax.swing.plaf.basic.BasicComboBoxUI$Handler fireContentsChanged():100, javax.swing.AbstractListModel setSelectedItem():88, javax.swing.DefaultComboBoxModel setSelectedItem():557, javax.swing.JComboBox ...
20-09-2007