I have 2 JComboBox's in my app and when I change the value of 1 combobox it has to do something else than when I change the other combobox. When I change the first, the values of the the second should be modified but when I change the second it should do nothing. So is there a way to see which combobox has been changed?
Thanks!
sure, you should check event.getSource()
to find the one you're interested in:
@Override
public void actionPerformed(ActionEvent event) {
Object src = event.getSource();
...
}
You should be able to differentiate them from the ActionEvent's getSource()
Object.
Alternatively, you can set a different "Action Command" using the setActionCommand() method and getActionCommand()
You can also directly add an anonymous actionListener to the combobox you need to listen for:
comboOne.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// make changes to comboTwo
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.