[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

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
0
mgcIT
Asked:
mgcIT
  • 3
  • 2
1 Solution
 
CEHJCommented:
A plain ActionListener can be added to the combo and in the handler you  can call getSelectedItem
0
 
objectsCommented:
combo.addItemListener(new ItemListener()
{
   public void       itemStateChanged(ItemEvent e)
   {
      // selection has changed

      if (e.getStateChange()==ItemEvent.SELECTED)
      {
          Object selected = e.getItem();
      }
   }
});
0
 
mgcITAuthor Commented:
in this example would selected = the actual item that was selected?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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

I'm referring to this.  
0
 
objectsCommented:
yes
0
 
mgcITAuthor Commented:
Thanks for the help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now