I am making JComboBox
in JTable
in Java Swing which have two items.
When I click on the combo box an ActionEvent
fires and my ActionListener
is notified.
When I select an item in the combo box the listener is called again.
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 + "--------");
}
});
When I click on the combo box, it shows the previously selected school_id
value.
After selecting an item in the combo box, it shows currently selected row school_id
value,
but I want it to show only currently selected school_id
value.
Any help is apreciated.