JComboBox selection actions on mouse and enter only

I am driving some processing off of selections in a JComboBox.

The ItemListener goes into action when the user mouse clicks on an item (this is good), but also when an item is arrowed through (bad).

I want to wait until the person hits enter before starting my processing.

Ideally the JComboBox popup could close before the start of my processing.

The direction I am currently headed: I notice that when the mouse clicks, and when enter is hit, the JComboBox popup closes. Since these are the 2 user events I want to respond to, this fact interests me greatly. Is there any way to see and use the event of the popup closing?

Note: I don't care so much about the direction I am thinking now as much as a solution to the overall problem.

[794 byte] By [jnaue] at [2007-9-26 4:00:24]
# 1
have you tried using an action listener instead of an ItemListener ?
simon_orange at 2007-6-29 12:55:19 > top of Java-index,Desktop,Core GUI APIs...
# 2
yes, of course
jnaue at 2007-6-29 12:55:19 > top of Java-index,Desktop,Core GUI APIs...
# 3

Try to register a KeyListener to the JComboBox or to its editor (if its editable) and react to the keyReleased Event. In the corresponding listener method you have to query the key typed and react to the ENTER

key being pressed. Also get away from the ItemListener as the JComboBox / ItemListene combination is not the best the guys at sun farbricated...

SMachhausen at 2007-6-29 12:55:19 > top of Java-index,Desktop,Core GUI APIs...
# 4
Does anyone have a solution for this?Adding a key listener to trap any key events that im interested in (Enter, Tab, etc), plus a mouse listener for the case when an item is selected with the mouse seems a bit messy...Thanks.
muppet. at 2007-6-29 12:55:19 > top of Java-index,Desktop,Core GUI APIs...
# 5
Well, the OP just wanted a way to do something when the popup closed. You canuse JComboBox.addPopupMenuListener to add a listener, and just do what youwant in the popupMenuWillBecomeInvisible method.: jay
JayDS at 2007-6-29 12:55:19 > top of Java-index,Desktop,Core GUI APIs...