jeudi 19 mars 2015

ActionListener running without action

I have 2 Jcomboboxes(drop down list) with checkboxes. So user can select multiple items using drop down list. I can select one or multiple items from first combo box.It is working nicely. Then I select one or multiple items from second combo box.It is also working nicely. Then if I again select item from first combo box then actionlistener running two times.First time running according to user action. but second time without user action.Why this happen? I used separate names and separate actionlisteners for each combobox.Thanks for any help.



ActionListener a0 = new ActionListener() {
public void actionPerformed(ActionEvent event) {

CellItem item = (CellItem) table.getValueAt(row, 0);
CheckComboStore store = (CheckComboStore) categoryComboBox0
.getSelectedItem();
CheckComboRenderer ccr = (CheckComboRenderer1) categoryComboBox0
.getRenderer();
ccr.checkBox.setSelected((store.state = !store.state));
if (store.state) {
arrlist0.add(store.id);
reflist0.add(store.ref);

} else {
if (reflist0.contains(store.ref)) {
arrlist0.remove(store.id);
}
}

item.setReferenceObject(arrlist0);

table.setValueAt(item, row, 0);
table.setValueAt(new CellItem(categoryComboBox0), row,
column);

}
};
categoryComboBox0.addActionListener(a0);

setComponent(categoryComboBox0);

return categoryComboBox0;
}


I got help this http://ift.tt/1xiHjf4 url to create dropdown list with checkboxes. I added user entered items (id),status(true or false) and reference (1,2,3,4) into arraylists.If user unchecked once checked values then I removed that item from the list checking its reference.





Aucun commentaire:

Enregistrer un commentaire