How to change selection listener in JComboBox

0 votes

I'm trying to get an event to fire whenever a choice is made from a JComboBox.

The problem I'm having is that there is no obvious addSelectionListener() method.

I've tried to use actionPerformed() but it never fires.

Short of overriding the model for the JComboBox I'm out of ideas.

How do I get notified of a selection change on a JComboBox?

Nov 15, 2018 in Java by Neha
• 6,300 points
878 views

1 answer to this question.

0 votes

It should respond to ActionListeners, like this:

combo.addActionListener (new ActionListener () {
    public void actionPerformed(ActionEvent e) {
        doSomething();
    }
});
answered Nov 15, 2018 by Frankie
• 9,830 points

Related Questions In Java

+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 79,578 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,230 points
1,925 views
0 votes
5 answers

How to compare Strings in Java?

String fooString1 = new String("foo"); String fooString2 = ...READ MORE

answered Jul 12, 2018 in Java by Daisy
• 8,120 points
2,182 views
+1 vote
2 answers

How to generate random integers within specific range in Java?

You can achieve that concisely in Java: Random ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
985 views
0 votes
1 answer

revalidate() vs repaint() in Java Swing

You need to call repaint() and revalidate() both in order ...READ MORE

answered Sep 20, 2018 in Java by code.reaper12
• 3,500 points
10,240 views
0 votes
1 answer

Fetching screen resolution using Java

You can fetch the screen resolution using the Toolkit.getScreenSize() method ...READ MORE

answered Sep 20, 2018 in Java by anto.trigg4
• 3,440 points
4,327 views
0 votes
1 answer

Describe Heavy Weight Components Mean In Java Programming?

Heavy weight components like Abstract Window Toolkit ...READ MORE

answered Nov 28, 2018 in Java by Frankie
• 9,830 points
1,575 views
0 votes
1 answer

First panel added to a frame disappears

The default layout of a JFrame (or more specifically ...READ MORE

answered Mar 1, 2019 in Java by developer_1
• 3,320 points
1,174 views
0 votes
1 answer

How to create a temporary directory/folder in java?

If you are using JDK 7 use ...READ MORE

answered Aug 28, 2018 in Java by Frankie
• 9,830 points
6,101 views
0 votes
1 answer

How to force garbage collection in Java?

Your best option is to call System.gc() which simply ...READ MORE

answered Nov 15, 2018 in Java by Frankie
• 9,830 points
830 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP