Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JComboBox - how to add a listener

Posted on 2006-06-19
6
Medium Priority
?
293 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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

877 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