選擇項目,我在的Java Swing JTable
其中有兩個項目使JComboBox
。如何從JComboBox中
當我點擊組合框中選擇一個ActionEvent
火災和我的ActionListener
通知。
當我在組合框中選擇一個項目時,再次調用監聽器。
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String school_id = null;
JComboBox comboBox = (JComboBox) e.getSource();
String access_value = comboBox.getSelectedItem().toString();
final int selectedRowIndex = table.getSelectedRow();
System.out.println("selected row: " + selectedRowIndex);
if(selectedRowIndex == -1) {
System.out.println("returned value");
return;
} else {
school_id = (String) table.getModel().getValueAt(selectedRowIndex, 2);
}
if(adminDaoImpObj.updateSchoolAccount(school_id, access_value) > 0) {
//System.out.println("updated success");
} else {
System.out.println("fail");
}
System.out.println(school_id + "--------");
}
});
當我點擊組合框時,它顯示先前選擇的school_id
值。
在組合框中選擇一個項目後,它顯示當前選中的行school_id
值,
,但我希望它僅顯示當前選擇school_id
值。
任何幫助是apreciated。
我想你必須使用另一個Listener類型。 – Diversity
你必須使用ItemChangeListener:看看這裏:http://stackoverflow.com/questions/58939/jcombobox-selection-change-listener – Diversity
郵報[SSCCE(http://sscce.org),顯示您的問題。 –