This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes On the JComboBox - ItemListener becomes the events tow times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "On the JComboBox - ItemListener becomes the events tow times" Watch "On the JComboBox - ItemListener becomes the events tow times" New topic
Author

On the JComboBox - ItemListener becomes the events tow times

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hallo
I have a JComboBox and I listen it with a ItemListener implementation.What is wonder me is that the events are coming two times(every time for each state select or deselect).Why two times ?


SCJP, SCJD, SCWCD, OCPJBCD
Geza Kovacs
Greenhorn

Joined: Nov 10, 2004
Posts: 4
Originally posted by Mihai Radulescu:
Why two times ?


You will receive one or two ItemEvents when the selection changes. The first event is "item deselected" (the old selection). If the original selection is empty, you won't receive this event. The second event is "item selected" (only if the new selection isn't empty).
[ November 10, 2004: Message edited by: Geza ba ]
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

That's logic thanks.There was also a small bug in my code, the listener was added two(oops) times.
Thanks !
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: On the JComboBox - ItemListener becomes the events tow times
 
jQuery in Action, 3rd edition