🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #11191

Re: JComboBox and ActionListener

#11191
From: Rich Wilkman
Date: Thu, 24 Jun 1999 00:00
54 lines
2760 bytes
Omer:

ItemStateChanged will always be fired twice (and there are several other
events in this pattern).  This is not a bug at all.  Here's what
happens.

You have a list with two items (it works the same with one, but it's
easier to think about it with two items).  By default, one of them is
selected and you click on the other one.  The item that was originally
selected will fire a StateChanged because, well, it's state has changed
to deselected.  The item you clicked on will fire the event for the
reverse reason; it went from de-selected to selected.

You need to dig a little deeper into the event.  If you only care about
the widget that was selected check the event type/id and ignore it if
the type was DESELECTED.  This doesn't stop the event from being fired
twice, but it stops your code inside the event handler from being
executed twice.

-Rich

Omer Azhar Qureshi wrote:
> 
> Peter,
> i had the same problem.... even the "itemStateChanged" event is fired twice
> & when ever the selected item of the comboBox is changed whic was not
> requied at all in my case as i had to get data from the servlet on the
> itemChange which was done in a thread.... so subsequiently the thread was
> called twice & the servlet as well which took a long time to trak down &
> work around... ive search sun's site for such a bug report but there dosent
> seem to be any....
> ive not been able to restrict it from beeing called twice but i kinda fool
> it the second time using an instance variable (boolean) & let it go on
> alternate calls, but this is not a solution.... do post any solution that u
> come up with....
> 
> hope this helps
> regards
> Oaq

-- 

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rich Wilkman
Senior Quality Assurance Engineer
Borland JBuilder Team

If you see something that looks like an opinion up there,
it's mine and mine alone.

Mail sent to me from the newsgroups won't bounce but will
be ignored.  If I have time, I'll respond, but you  have
a better chance if you confine your posts to the newsgroups
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical Details
Message-ID: <377261F0.E5A88B68@inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3770C13D.D349D879@terren.com> <7ksvat$c3111@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,7f6f7d3b5376db9d
X-Google-Attributes: gid111d45,public
From: Rich Wilkman <rwilkman@inprise.com>
Subject: Re: JComboBox and ActionListener
Date: 1999/06/24
Message-ID: <377261F0.E5A88B68@inprise.com>
X-Deja-AN: 493429165
Content-Transfer-Encoding: 7bit
References: <3770C13D.D349D879@terren.com> <7ksvat$c3111@forums.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing