1

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 .

Terance Wijesuriya
  • 1,928
  • 9
  • 31
  • 61

1 Answers1

5

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;
}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97