Siddharth Raina Siddharth Raina - 5 months ago 49
Java Question

How to make a JTable non-editable

How to make a

non-editable? I don't want my users to be able to edit the values in cells by double-clicking them.

Any help would be greatly appreciated.



You can use a TableModel.

Define a class like this:

public class MyModel extends AbstractTableModel{
    //not necessary

actually isCellEditable() is false by default so you may ommit it. (see:

Then use setModel() method of your JTable.

JTable myTable = new JTable();
myTable.setModel(new MyModel());