JComboBox - how to add a listener

I want to run a method when a new item is selected from the JComboBox.  I beleive I use the selectedItemChanged() method but not sure how.  How do I set up the listener to do this?  

Thanks
LVL 18
mgcITAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
combo.addItemListener(new ItemListener()
{
   public void       itemStateChanged(ItemEvent e)
   {
      // selection has changed

      if (e.getStateChange()==ItemEvent.SELECTED)
      {
          Object selected = e.getItem();
      }
   }
});
0
 
CEHJCommented:
A plain ActionListener can be added to the combo and in the handler you  can call getSelectedItem
0
 
mgcITAuthor Commented:
in this example would selected = the actual item that was selected?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mgcITAuthor Commented:
>> Object selected = e.getItem();

I'm referring to this.  
0
 
objectsCommented:
yes
0
 
mgcITAuthor Commented:
Thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.