Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable user edit in JTable [duplicate]

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?

like image 551
Parag Avatar asked Mar 29 '12 04:03

Parag


People also ask

How can we disable the cell editing inside a JTable in Java?

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.

How do you make a cell editable in JTable?

jTableAssignments = new javax. swing. JTable() { public boolean isCellEditable(int rowIndex, int colIndex) { return editable; }};


1 Answers

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.

like image 113
Rahul Borkar Avatar answered Sep 24 '22 10:09

Rahul Borkar