2

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.

Patrick
  • 17,669
  • 6
  • 70
  • 85
Bert De Geyter
  • 125
  • 1
  • 1
  • 7

1 Answers1

3

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.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373