1

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!

4

3 回答 3

3

也可以直接在需要监听的combobox中添加匿名actionListener:

comboOne.addActionListener(new ActionListener() 
{
    public void actionPerformed(ActionEvent e) 
    {
        // make changes to comboTwo
    }
});
于 2013-10-29T23:07:02.707 回答
3

当然,您应该检查event.getSource()以找到您感兴趣的那个:

@Override
public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    ...
}
于 2013-10-29T23:01:16.807 回答
3

您应该能够将它们与 ActionEvent 的getSource()对象区分开来。

或者,您可以使用setActionCommand()方法和getActionCommand()设置不同的“操作命令”

于 2013-10-29T23:01:42.967 回答