Help: JComboBox and Events


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Help: JComboBox and Events

  1. #1
    Join Date
    Feb 2003
    Posts
    1

    Question Help: JComboBox and Events

    Hi, this is my first time here and i was just wondering if anyone could answer a question for me.
    How do you use events such as ItemListener or ActionListener with JComboBoxs? Say if I have a JComboBox

    JComboBox jc = new JComboBox();
    jc.addItem("track a");
    jc.addItem("track b");
    jc.addItem("track c");

    Container contentPane = getContentPane();
    //setLayout

    jc.addItemListener(this);

    contentPane.add(jc);

    I know how to setup a combo box but i don't know how to get it to do something. What I want to be able to do is that if the users chooses "track a" from the JComboBox , then it does something else. I've been looking for a way to get the action to choose something.
    I know you use getSource() and things like that but , as you can see, I'm a bit confused about it. If anyone know any good sites for JComboBox tutorials or could help , I would be very grateful.

    So my question is, How do I get an ItemListener to get the chouice from the JComboBox and then do something with that.
    Thanks for your time.

  2. #2
    Join Date
    Nov 2002
    Posts
    59
    The ActionListener should do it...check out http://java.sun.com/docs/books/tutor.../combobox.html for a tutorial that includes using listeners with comboboxes. Hope that helps, if not, come back and let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center