Forums Register Login

differentiate between combo box

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
never mind, ignore this...
+Pie Number of slices to send: Send
The ItemEvent class inherits a method "getSource()" from the EventObject. Try using that.

Regards
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Hi Gregg.

You can do something like this.


Hope that helps.

Mark.....
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

Rob Prime wrote:I'll put on my Campbell cap:

I'm sure I say more things than that
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1075 times.
Similar Threads
Handling Chinese characters while retriving fromDB using JDBC
Verify the combobox
Problem with updating look and feel colors of swing components dynamically
render combo box
Registering 2 combo Boxes to listener separately
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:06:11.