Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Double click JComboBox to edit

843805Nov 4 2005 — edited Nov 10 2005
I have an editable JComboBox, but I'd like to make it so that it doesn't edit the selected value until the user has double clicked in the selected field area. Additionally, I have a button to create a new item in the combo box, and I would like it automatically edit this new field. Finally, I'd like to set things up so that if the user hits ESC while editing, they will get out of editing mode, and the value of the selected item will revert to it pre-edit value.

I've looked at the ComboBoxEditor and BasicComboBoxEditor javadocs, and don't see any good way to do this. Using a combo box inside a JTable sort of does this, since the DefaultCellEditor has the setClickCountToStart() method. That is basically what I am after.

In Summary, this is basically what I want to do:

On double-click:
save current value
make combo box editable.

on Enter:
save current value in editor.

on ESC of Lose Focus:
discard current value
re-set previous value.


Thanks,
Mike Ryan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2005
Added on Nov 4 2005
1 comment
292 views