How to avoid firing actionlistener event of JComboBox when an item is get added into it dynamically in java?

You could remove the action listener before you add the new elements, and add it back once you’re done . Swing is single threaded so there is no need to worry about other threads needing to fire the listener.

Your listener could probably also check if something is selected and take appropriate action if not. Better than getting a NPE.

Leave a Comment