File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple combo boxs - one ItemListener

 
Glen Iris
Ranch Hand
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have two combo boxs, I want to add a separate itemListener to each one so that a different method is called depending on which comboBox the user effects.

Is this possible?

Alternatively, in the itemStateChanged method, is there a way to find the identity of the calling combobox?
 
Roel De Nijs
Sheriff
Posts: 9098
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question and your title seems contradictory to me. In your title it seems you want multiple comboboxes and 1 ItemListener. But your question starts with "I have two combo boxs, I want to add a separate itemListener to each one"

Nonetheless both are possible. And if you want to identify the calling combobox, you have to choices:
1/ call getItem() on the ItemEvent instance of the itemStateChanged() method (a cast will be required)
2/ make a custom ComboItemListener class (which of course implements ItemListener and performs your business logic) and just pass a ComboBox to its constructor as an argument
 
Glen Iris
Ranch Hand
Posts: 168
Chrome Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solution 2 worked a treat. Thanks Roel.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic