Allain Lalonde Allain Lalonde - 1 year ago 266
Java Question

JComboBox Selection Change Listener?

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


The problem I'm having is that there is no obvious

I've tried to use
but it never fires.

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

How do I get notified of a selection change on a

Edit: I have to apologize it turns out I was using a misbehaving subclass of
, but I'll leave the question up since your answer is good. Commence the vote down. :)

Answer Source

It should respond to ActionListeners, like this:

combo.addActionListener (new ActionListener () {
    public void actionPerformed(ActionEvent e) {

@John Calsbeek rightly points out that addItemListener() will work, too. You may get 2 ItemEvents, though, one for the deselection of the previously selected item, and another for the selection of the new item. Just don't use both event types!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download