Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox

 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • 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.
 
David Crossett
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic