Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox ActionEvent  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a combo box that gets info from the DB whenever a customer is chosen.
Sometimes I need to set the selected item on this combo box, but don't want
to go get the data from the DB again.
When I setSelectedItem() on the combobox, it gets the data again, and I don't want it to.
Is there any way to tell the difference between a user actually
choosing the customer, and me setting the customer using setSelectedItem()?
Thanks!
 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a user is selecting an element from the comboBox then it fires an actionEvent.
So in case of user this might be helpful.

Hope this helps.
Thank you
Garandi
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply!
Right now, I do have an actionListener added to the combo box.
And when the user chooses a customer, it fires an action event and gets the
data from the DB. This is OK.
However, in my code, I am doing a 'setSelectedItem("String")'on this combobox.
This also triggers an action event and then goes and gets the data again from the DB. I don't want to get the data from the DB if the action event came from me doing a setSelectedItem("String") on the combobox.
I only want it to get the data if the user has chosen a customer.
How can I tell the difference between the two action events?
Thanks!
 
Tim Troy
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do ugly stuff like what you see below. If there is a more graceful way to do this, please share.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!