This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Event handling with JComboBoxes  RSS feed

 
Jack Drowder
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JComboBox, and I've registered an ActionListener to it. I want actionPerformed() to run only when the user selects an option from the combo box, but I have code that adds new options to the combo box, and this also triggers an ActionEvent. How can I detect ActionEvents caused by the user clicking an option so the code in actionPerformed() doesn't run when new options are added?

I hope that makes sense!

Thanks!
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack Drowder wrote:I want actionPerformed() to run only when the user selects an option from the combo box...


Well, normally you would use an ItemListener, whose whole purpose is to be notified when the combo box's selected item changes. So I would recommend the ItemListener, rather than trying to twist things so that your ActionListener has to do that work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!