Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Registering 2 combo Boxes to listener separately

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have 2 combo boxes in swings.I want to perform different operations on actions of both of the combo boxes.
##Now, I am registering them to action listener and identifying action through
if (command.equals("comboBoxChanged"))
But : Through this not able to distinguish 2 combo boxes separately
Plz tell me how can i perform different actions for different combo boxes
Bye
 
Campbell Ritchie
Marshal
Posts: 52664
122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't "register 2 combo Boxes to listener seperately."

You register 2 Listeners to the combo Boxes.
If you look up JComboBox in the API specification, it has three methods which add different Listeners. You can add those listeners, one to JComboBox "a," and a different one to JComboBox "b."

We have had discussions about how to add Listeners on this forum in the last week or so, here, and here, for example.

Try those threads, and the Java tutorial, and tell us how you got your Listeners to work.

CR
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanx for the reply...
I want to take the index of the selected item of combo box.
## I am doing : setSelectedIndex(int) and it is starting the index of 1st element of combo box with 0 ,whatever be the parameter inside setSelectedIndex.
##Plz tell me how can i get the index inside the combo box
Thanx
 
Campbell Ritchie
Marshal
Posts: 52664
122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's all in the API, there are several get methods which I think will fit the bill.

BTW: I never noticed that JComboBox has its own actionPerformed() method. Have you tried that? It is quite unusual for a Component to have that method already in it. It implements the appropriate interface. So you might get away without registering a Listener to a ComboBox at all

CR
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!