• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

ComboBox ItemListener calling twice..

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<aircode>

 
Vijay Vaddem
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked!

Thanks.....
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic