Reputation: 1986
I have a JTable
which has DefaultTableModel
. Now I want to change table column headers and columns data types(eg :- Boolean,String,Object,etc). I try to do as following .
DefaultTableModel model = (DefaultTableModel) list_table.getModel();
list_table.setModel(new javax.swing.table.DefaultTableModel(new Object[][]{}, new String[]{"", "ID", "Name", "Age","Address", "Contact", "Gender", "Civil Status" }));
updateTable();
The " " column object type should be boolean.But I couldn't change object type to a Boolean from this.Also I run this on threaded environment.
Have any ideas .
Upvotes: 1
Views: 1437
Reputation: 48287
you need to override the getColumnClass
, for example, if the column 5 (0 index) is a Boolean you can do this:
@Override
public Class<?> getColumnClass(int columnIndex) {
Class classType = String.class;
switch (columnIndex) {
case 4:
classType = Boolean.class;
break;
}
return classType;
}
Upvotes: 5