itemStateChanged() Is Fired Twice

This is indeed a tale of two mysteries. I was mystified upon seeing why my JComboBox ItemListener’s itemStateChanged() event method gets fired twice. There was only one way to solve it and that was to Google for it.

And the answer? Two events are fired whenever you select an item in the JComboBox: the deselect event and the select event.

If you insist in using an ItemListener for this, you would have to place an if statement within the itemStateChanged() method to handle only select or deselect events.

Frankly, I would suggest you use an ActionListener instead.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *