Java – Disable user edit in JTable

editjavajtableswing

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?

Best Solution

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.