Take the 2-minute tour ×

My program has the ability to change the selected item of my combobox. But how can I know if the item change has been caused by an human mouse click on the item itself or by my program.

I'm pretty much looking for a MouseListener that can be added to the items of the JComboBox and not the JComboBox itself.

share|improve this question
Can you show us code so we can play with it? Also, did you considered using ItemListener? –  brano Nov 4 '12 at 20:13
add comment

1 Answer

up vote 3 down vote accepted

A JComboBox is a compound component, and it is highly recommended that you avoid using low-level listeners such as a MouseListener with it. Instead why don't you disable your selection listener (perhaps you're using an ActionListener) when the code selects an item, and then re-enable it after the selection is done. Thus you'll know that any activity by the ActionListener is from a user's choice. You can disable and enable the listener by either removing and re-adding it, or by giving using a boolean variable that allows the listener to react only when the boolean is true.

share|improve this answer
add comment

Your Answer


