aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes differentiate between combo box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "differentiate between combo box" Watch "differentiate between combo box" New topic
Author

differentiate between combo box

Ar vinoth
Greenhorn

Joined: Jun 24, 2009
Posts: 2
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.


vino
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1958
    
    7

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD
Mikko Kohtamäki
Ranch Hand

Joined: Dec 13, 2008
Posts: 112
never mind, ignore this...
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
The ItemEvent class inherits a method "getSource()" from the EventObject. Try using that.

Regards


Experience and talent are independent of age
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

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.


GenRocket - A Test Data Generation Platform
Mark O'Neal
Greenhorn

Joined: Jul 23, 2009
Posts: 5
Hi Gregg.

You can do something like this.


Hope that helps.

Mark.....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Rob Prime wrote:I'll put on my Campbell cap:
I'm sure I say more things than that
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: differentiate between combo box
 
Similar Threads
Verify the combobox
render combo box
Problem with updating look and feel colors of swing components dynamically
Registering 2 combo Boxes to listener separately
Handling Chinese characters while retriving fromDB using JDBC