JDK-6428549 : REGRESSION: Text entered in the Editable JComboBox got cleared when the Enter Key is pressed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-05-22
  • Updated: 2011-01-19
  • Resolved: 2006-08-18
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.
6 b96Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
The entered text in a editable JComboBox, while the popup was visible, got cleared when the enter key pressed.

Steps to reproduce:

1. Run the attached program
2. A JFrame with a table and JComboBox at the bottom will displayed
3. Click on the JComboBox next to the label "Editable Combobox"
4. Make sure the Popup of the JComboBox is visible
5. Now type something on the editable field and press enter

If the entered text got disappeared then the bug is reproduced. 

Build Information: Mustang build b84

I tried the same test on Tiger, which works fine. Hence this is a regression.
I don't see any attached program. Where is it?

SUGGESTED FIX The fix consists of the three parts: - The bug fix itself. - Fix for the tightly related problem with selection of items by mouse when combo box is a cell renderer in JTable. - I implemented Peter Zhelezniakov's idea. Handling of the ENTER key by an editable JComboBox, when popup is visible, now depends on the "ComboBox.isEnterSelectablePopup" LaF property. All LaFs, except GTK, leave editor value. GTK LaF always selects the item, selected in the popup.

EVALUATION I think it is a regression from the fix for the 4765319 bug. The problem is in the BasicComboBoxUI.Actions.actionPerformed() method: ... else if (key == ENTER) { if (comboBox.isPopupVisible()) { // Forces the selection of the list item comboBox.setSelectedIndex(ui.popup.getList().getSelectedIndex()); ... If the ENTER key was pressed and popup is visible, the code tries set the combo's text with the selected item in popup. But if the combo's text was changed manually, there is no any selected item in popup and the combo's text becomes empty.

SUGGESTED FIX See webrev: http://javaweb.sfbay/jcg/1.6.0-mustang/swing/6428549/

EVALUATION I can reproduce the bug under mustang. Under tiger all is OK.