• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

differentiate between combo box

 
Ar vinoth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,

i am using two combo box in same program and i am adding both to itemListener class. when the user selects the the item in combo box i need to know from which combo box he is selecting.. based on that i will perform some action. I got struck here. Help me.

bye,
vino.
 
K. Tsang
Bartender
Posts: 3457
14
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

About your question, you need 2 item listeners, one listener for each combo box. If you don't whatever thing you do with the first combo box is also done for the 2nd combo box... and you don't want that.
 
Mikko Kohtamäki
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never mind, ignore this...
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ItemEvent class inherits a method "getSource()" from the EventObject. Try using that.

Regards
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Welcome to the Ranch.

About your question, you need 2 item listeners, one listener for each combo box. If you don't whatever thing you do with the first combo box is also done for the 2nd combo box... and you don't want that.


That's not entirely true. You can use the same listener for multiple controls. There are a few ways to determine which one triggered the event.

WARNING: untested code being shown.





In the latter example, it assumes you set the name of each control when constructing your combo boxes.
 
Mark O'Neal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg.

You can do something like this.


Hope that helps.

Mark.....
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the fact that you'll need to make the combo boxes either final or instance references, I'll put on my Campbell cap:
Don't use == true or == false; simply use or
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:I'll put on my Campbell cap:
I'm sure I say more things than that
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic