Solved

JComboBox - how to add a listener

Posted on 2006-06-19
6
275 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
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
in this example would selected = the actual item that was selected?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 18

Author Comment

by:mgcIT
Comment Utility
>> Object selected = e.getItem();

I'm referring to this.  
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
yes
0
 
LVL 18

Author Comment

by:mgcIT
Comment Utility
Thanks for the help.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now