Hi all, I'm currently trying to solve a problem with a JList. I've got an actionPerformed event applied to the JList (also tried the item updated event but it has the same effect), and whenever this event is fired, (i.e. the user makes a selection), something happens. Now, the problem is that when the list is being populated, it seems to fire the event too - thus creating problems for me.
Is there a way to stop the JList from firing the actionPerformed or itemStateChanged event when the contents is updated?
You can set a flag while you are altering the contents of the control, such as initialized=false; and then set it to true when you are finished. Your listener can simply ignore events while you are updating the contents by checking that flag.
but as Darryl said (Java Forum) remove and add just if needed, if you'll able to set boolean flag (Ezzeral sugestion), then you'll be able same way remove&add whole Listener, that's good concept and the safiest