Siddharth Raina Siddharth Raina - 1 year ago 77
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.


Answer Source

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());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download