I've made my AbstractTableModel
but my checkbox in table is not editable. When I click on it, nothing changes, my checkbox in column "Done" is still unchecked. How can I make it checkable ? Also I need to save Order Number when CheckBox is checked, but I dont know how to do it...
Here is picture of my table
Here is my code of TableModel:
public class KitchenTableModel extends AbstractTableModel {
private ArrayList<WrapperKitchen> hrana;
public KitchenTableModel(ArrayList<WrapperKitchen> hrana2) {
this.hrana = hrana2;
}
@Override
public int getColumnCount() {
return 8;
}
@Override
public int getRowCount() {
return hrana.size();
}
public String getColumnName(int columnIndex) {
switch (columnIndex) {
case 0:return "Order number";
case 1:return "Room";
case 2:return "Category";
case 3:return "Meal";
case 4:return "Quantity";
case 5:return "Note";
case 6:return "Order time";
case 7:return "Done";
}
return null;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
WrapperKitchen jelo = hrana.get(rowIndex);
switch (columnIndex) {
case 0:return jelo.getIdUslugaHrana();
case 1:return jelo.getBrojSobe();
case 2:return jelo.getNazivKategorija();
case 3:return jelo.getNazivHrane();
case 4:return jelo.getKolicina();
case 5:return jelo.getNapomena();
case 6:return jelo.getDatumVrijeme();
case 7:return jelo.getIzvrseno();
}
return null;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 7)
return Boolean.class;
return super.getColumnClass(columnIndex);
}
@Override
public boolean isCellEditable(int rowIndex, int colIndex) {
return (colIndex == 7);
}
}
You have to override
setValueAt()
inAbstractTableModel
cause default implementation is empty.An example: