Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JComboBox - how to add a listener

Posted on 2006-06-19
6
Medium Priority
?
288 Views
Last Modified: 2010-03-31
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
Comment
Question by:mgcIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16938133
A plain ActionListener can be added to the combo and in the handler you  can call getSelectedItem
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16938303
combo.addItemListener(new ItemListener()
{
   public void       itemStateChanged(ItemEvent e)
   {
      // selection has changed

      if (e.getStateChange()==ItemEvent.SELECTED)
      {
          Object selected = e.getItem();
      }
   }
});
0
 
LVL 18

Author Comment

by:mgcIT
ID: 16938611
in this example would selected = the actual item that was selected?
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 18

Author Comment

by:mgcIT
ID: 16938612
>> Object selected = e.getItem();

I'm referring to this.  
0
 
LVL 92

Expert Comment

by:objects
ID: 16938793
yes
0
 
LVL 18

Author Comment

by:mgcIT
ID: 16938893
Thanks for the help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question