Either populate the list before you add the listener or set a boolean flag initialized and check if (initialized) {... in your listener.
Edit: You may check to see if ListSelectionListener works better for your needs also. I wouldn't think that one would fire any event as the model is filled.
Ezzaral
null
16,111 posts since May 2007
Reputation Points: 3,292
Solved Threads: 873
Skill Endorsements: 28
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.
Ezzaral
null
16,111 posts since May 2007
Reputation Points: 3,292
Solved Threads: 873
Skill Endorsements: 28
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
mKorbel
Nearly a Posting Virtuoso
1,215 posts since Feb 2011
Reputation Points: 482
Solved Threads: 239
Skill Endorsements: 12
Are you actually using the AWT List component? JList doesn't provide methods to add ActionListener or ItemListener.
JList just uses the ListSelectionListener which behaves a bit differently.
Ezzaral
null
16,111 posts since May 2007
Reputation Points: 3,292
Solved Threads: 873
Skill Endorsements: 28
Question Answered as of 2 Years Ago by
Ezzaral
and
mKorbel