Disable user edit in JTable

Parag picture Parag · Mar 29, 2012 · Viewed 71k times · Source

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?

Answer

Rahul Borkar picture Rahul Borkar · Mar 29, 2012

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.