Can you tell me if I should be doing this differently? I need to make the last cell on my data rows a checkbox that is tied back to an object I will remove form the list when a delete button is clicked. When I manually create the TableModel in code and add a checkbox it renders in the cell as a "to-string" of the object rather than an actual checkbox.
So the question: is there another way to do this to make the CheckBox show as an actual checkbox instead?
String[] columnNames = {"Type","Qty","Raw TB","Usable TB","Del?"};
Object[][] cells = {{"TOTAL","","0","0",""},{"DD4500",1,0f,0f,new CheckBox()}};
Table cbSummaryTable = findSummaryTable(buildContainer);
TableModel tableModel = new DefaultTableModel(columnNames,cells);
cbSummaryTable.setModel(tableModel);
Edit: I tried the suggestion from @ShaiAlmog, and while it looked promising (and reminded me of something I saw elsewhere) it seems to not have worked for some reason. the table now just says "true" and "false". I also tried a trick I'd seen about overriding TableModel to make a cell editable and that didn't help either.
New Code:
private void clearCBSummaryTable(Container buildContainer){
String[] columnNames = {"Type","Qty","Raw TB","Usable TB","Del?"};
Object[][] cells = {{"TOTAL","",0f,0f,Boolean.TRUE},{"DD4500",1,0f,0f,Boolean.FALSE}};
Table cbSummaryTable = findSummaryTable(buildContainer);
TableModel tableModel = new DefaultTableModel(columnNames,cells){
@Override
public boolean isCellEditable(int row, int column) {
if (row >= 2 && column == 4){
return true;
}else {
return super.isCellEditable(row, column);
}
}
};
cbSummaryTable.setModel(tableModel);
}
Anything else I can do to help the Table recognize and render the Boolean as a Checkbox?