I am currently working on an attendance system where I'll use jTable and add jCheckbox in it. However, I have no idea how to do this.
What should I do to add jCheckBox in my jTable. The data in my jTable is acquired from a database.
I have tried using this code but the table doesn't show the data from my database and still doesn't have a checkbox on it.
public void Update_table(int Column, int ColumnBoolean, DefaultTableModel model) {
try {
String sql = "select * from student_info";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
Attendance.setModel(DbUtils.resultSetToTableModel(rs));
Object[] files = new Object[Column];
while (rs.next()) {
for (int i = 1; i <= Column; i++) {
if (i == ColumnBoolean) {
files[ColumnBoolean - 1] = Boolean.FALSE;
} else {
files[i - 1] = rs.getObject(i - 1);
}
model.addRow(files);
}
Attendance.updateUI();
rs.close();
}
JCheckBox check = new JCheckBox();
Attendance.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(check));
Attendance.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer());
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}