2
我试图监听Java JComboBox中的选择更改。我曾尝试使用一个ActionListener但问题是这样的:行动听众都这样做Java JComboBox监听更改选择事件
public void actionPerformed(ActionEvent e){
JComboBox<String> source = ((JComboBox<String>)e.getSource());
String selected = source.getItemAt(source.getSelectedIndex());
/*now I compare if the selected string is equal to some others
and in a couple of cases I have to add elements to the combo*/
}
东西正如你可以看到,当我需要的元素添加到组合的另一个事件被触发,actionPerformed方法是再次呼吁,即使我不希望这样,代码可以循环... :( 有什么办法来听,而不是选择更改为普通更改事件? 感谢
http://stackoverflow.com/questions/58939/jcombobox-selection-change-listener –