I need to put a checkbox in the column Present to mark when a guest arrives (it's a application to manage events)
String[] columns = {"Name","Present"};
Object[][] listInv = {
{"Giacomo Guilizzoni", false},
{"Guido Jack Guilizzoni", true},
{"Marco Botton", false},
{"Mariah Maclachlan", true},
{"Valierie Liberty", true}
};
DefaultTableModel dtm = new DefaultTableModel();
dtm.setDataVector(listInv, columns);
Jable tabla = new JTable(dtm);
TableColumn tcolumnas;
tcolumnas = tabla.getColumnModel().getColumn(0);
tcolumnas.setPreferredWidth(300);
jScroll = new JScrollPane(tabla);
tabla.setFillsViewportHeight(true);
I override the method getColumnsClass:
public Class getColumnClass(int columna) {
return Boolean.class;
}
Instead of show a JCheckBox is showing a string "true" or "false" What i'm doing wrong?
Edit:
it was as simple as this:
TableColumn tcolumnas = tabla.getColumnModel().getColumn(1);
columnas.setCellRenderer(tabla.getDefaultRenderer(Boolean.class));
tcolumnas.setCellEditor(tabla.getDefaultEditor(Boolean.class));