JCheckbox add JTable
Java gui 2016
public void showTableSinhVienSelect() {
// Clear table
table.setModel(new DefaultTableModel());
// Model for Table
DefaultTableModel model = new DefaultTableModel() {
public Class<?> getColumnClass(int column) {
switch (column) {
case 0:
return Boolean.class;
case 1:
return String.class;
case 2:
return String.class;
case 3:
return String.class;
case 4:
return String.class;
default:
return String.class;
}
}
};
table.setModel(model);
// Add Column
model.addColumn("Select");
model.addColumn("ID Sinh Vien");
model.addColumn("Ho Ten");
model.addColumn("Ngay Sinh");
model.addColumn("Gioi Tinh");
String sql = "SELECT * FROM project.sinhvien";
try {
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery(sql);
int row = 0;
while ((rs != null) && (rs.next())) {
model.addRow(new Object[0]);
model.setValueAt(false, row, 0); // Checkbox
model.setValueAt(rs.getString("idsv"), row, 1);
model.setValueAt(rs.getString("hoten"), row, 2);
model.setValueAt(rs.getDate("ngaysinh"), row, 3);
model.setValueAt(rs.getString("gioitinh"), row, 4);
row++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
Xem thêm cách xóa dữ liệu khi dùng checkbox trong java swing gui
0 nhận xét:
Post a Comment