When a JTable component is created, cell editing is enabled by default. How can I prevent the user from editing the content of a JTable?
By default, we can edit the text and modify it inside a JTable cell. We can also disable the cell editing inside a table by calling the editCellAt() method of JTable class and it must return false.
jTableAssignments = new javax. swing. JTable() { public boolean isCellEditable(int rowIndex, int colIndex) { return editable; }};
You can create a JTable using following code:
JTable jTable = new JTable() { private static final long serialVersionUID = 1L; public boolean isCellEditable(int row, int column) { return false; }; };
Basically what we are doing here is overriding isCellEditable
and always returning false from it. This will make a non editabe JTabel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With