• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JComboBox

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there,
I have used JComboBox in one of my programs, registered and implemented the ItemStateChangeListener for the same. It worked fine when I selected the combobox with mouse and keyboard. But when I try to select it through my program, it gets selected but the event doesnt get fired.
Would n e body tell me where I went wrong?
Thanks
Sai
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the API Documentation for ItemListener:


void itemStateChanged(ItemEvent e)
Invoked when an item has been selected or deselected by the user.


Sounds like it is working correctly to me.
 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi joe,
Thanx for ur reply.
The actual problem was, the event was not fired when the jcombobox was selected through my code. [ jCombobox.setSelected(true); //although the combox gets selected the event was not being fired. ]
Basically, I wanted to fire the event without using the mouse & keyboard manually. It should be performed through my code itself.
Hope u got me this time.
thanks
Sai
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome tot he Ranch sai,
from the JComboBox API:
protected void fireItemStateChanged(ItemEvent e)
Notifies all listeners that have registered interest for notification on this event type.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just guessing here, but it sounds to me like you're trying to fire an event with code? I'm sure there is a way to do that, but - again, I'm guessing - it sounds like just setting the combo-box to a new value isn't going to generate an actionEvent or stateChange. I thought those events were actually 'fired' through the operating system, and then handed off to our programs to be handled. If that's the case, then just changing it in code doesn't fire the event. I'll bet there is a way to - using code - simulate an event to be fired, so your code can handle it just as if a user made the change. In fact, I'm pretty sure that can be done. Anyone know how?
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic