I have created a JTable with the last (6th) column being a "Select" column which is having checkboxes. The checkboxes are added by overriding the getColumnClass method to return Boolean.class.
DefaultTableModel dtm = new DefaultTableModel(data, header){
@Override
public Class<?> getColumnClass(int col) {
if(col == 5){
return Boolean.class;
}
return super.getColumnClass(col);
}
};
Now I have to select some rows using these checkboxes and add some values from those selected rows to the database. This is the code I used.
DefaultTableModel model = (DefaultTableModel) tblInvoiceList.getModel();
for(int i=0; i<model.getRowCount();i++) {
if ((Boolean)model.getValueAt(i, 5))
paydao.updateInvoiceWithPayment(model.getValueAt(i, 0).toString());
}
When I loop through, the checked checkboxes are returning true. The unchecked ones are throwing NullPointerException. The exception occurs in the (Boolean)model.getValueAt(i, 5) part. How to make the unchecked ones return false??