wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to fire an initial event to JComboBox (ItemListener)? 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 "How to fire an initial event to JComboBox (ItemListener)?" Watch "How to fire an initial event to JComboBox (ItemListener)?" New topic
Author

How to fire an initial event to JComboBox (ItemListener)?

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
When I add an itemListener to the JComboBox,
It isn't called when its container/itself is first setup,
How can I call it once when the "JDialog" constructor is called?
Thanks
Jack
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

ItemListener is triggered when the item selection changes. Check out the API for any method which will let you programatically change the selection. Check if this fires the event.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Maneesh Godbole wrote:ItemListener is triggered when the item selection changes. Check out the API for any method which will let you programatically change the selection. Check if this fires the event.




Hello,
the itemStateChanged event is never called upon, when the setSelectedIndex(0) is set after it
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Jacky Luk wrote:How can I call it once when the "JDialog" constructor is called?


You need to call it at the end of your constructor.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Maneesh Godbole wrote:
Jacky Luk wrote:How can I call it once when the "JDialog" constructor is called?


You need to call it at the end of your constructor.


Like this?, but still doesn't select the first item... strange.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2225
    
    8
Where is your SSCCE???

If you say something doesn't work, then prove it. Post the SSCCE that you used to test the concept!!!

How hard is this to understand???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to fire an initial event to JComboBox (ItemListener)?