I have a JTable
of 5 columns and 20 rows. The headers are Name
, ID
, Present
, Absent
, Late
.
I would like to restrict the user from being able to tick all 3 boxes as obviously that wouldn't make sense.
What is the simplest way of doing this so that if for example, present is ticked, then absent is ticked the present value would change to false.
Here is a basic version of my code. lol please ignore how bad it is i'm fairly new to programming.
JPanel classRegPanel = new JPanel(null); //layout
Object data[][]= new Object[10][5];
String columns[]={"Name","ID","Present", "Absent", "Late"};
DefaultTableModel model = new DefaultTableModel(data, columns) {
boolean[] canEdit = new boolean[]{
false, false, true, true,true
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
@Override
public Class<?> getColumnClass(int columnIndex)
{
return columnClass[columnIndex];
}};
JTable table=new JTable(model);
JScrollPane scrollPane=new JScrollPane(table);
final Class[] columnClass = new Class[]
{
String.class, Integer.class, Boolean.class, Boolean.class,Boolean.class
};
public void Setup()
{
this.setLayout(new FlowLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.add(scrollPane);
this.setTitle("Register");
this.setSize(500,380);
this.setVisible(true);
this.setResizable(false);
}
public static void main(String[] args )
{
ClassRegister cr = new ClassRegister();
cr.Setup();
}