aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes ComboBox ItemListener calling twice.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ComboBox ItemListener calling twice.." Watch "ComboBox ItemListener calling twice.." New topic
Author

ComboBox ItemListener calling twice..

Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
Hi,

Whenever a item is selected from JComboBox, the itemListener
method is called twice..... !!???

Why is it happening, i need this method to be called only once with
the current selected item. But its calling this method with both, current
and previous selected item...

here is the code...

sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
Hi vijay,

The behavior of ItemListener is like that only.
It will call itemStateChanged two times because,
one of the item lost focus,
another one gains focus.
so it will call two times.

My suggestion is use ActionListener , and write actionPerformed like this


Hope This Helps.
All The Best
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
<aircode>

Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
It worked!

Thanks.....
Reyada Wolak
Greenhorn

Joined: Mar 28, 2009
Posts: 11
sasi kala wrote:Hi vijay,

The behavior of ItemListener is like that only.
It will call itemStateChanged two times because,
one of the item lost focus,
another one gains focus.
so it will call two times.

My suggestion is use ActionListener , and write actionPerformed like this


Hope This Helps.
All The Best


i tried to setFocusable(false) and it works just fine.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

I think you missed the point, and also that this question was asked and resolved 5 years ago.

sasi kala's terminology was off. One item loses the selection, and the other gains it. Not focus.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ComboBox ItemListener calling twice..