Neelam Sharma
Neelam Sharma

Reputation: 2855

JComboBox Working

I have one combo box which contain one item let say "a". I want to call the action listener of that combo box to be called only when manually selection of item "a" is done. I also tried ItemStateChanged, but it works similar to Action Listener.

How can I do it?

Upvotes: 0

Views: 505

Answers (2)

Andrei0427
Andrei0427

Reputation: 573

How about making 2 actionlisteners, one will see if the 'a' is selected and if it is it will invoke the second one

Upvotes: 0

phsym
phsym

Reputation: 1384

I don't think you can listen to events only for one ComboBox Item, but when listening on the whole combo box, in the callback you can check the selected item before processing the event (or ignoring it).

In the exemple provided by Sumit Singh, check the affected item

// Get the affected item
Object item = evt.getItem();

//check item
if(item == <the item you want to watch>)
{
    //process
}

Upvotes: 1

Related Questions