jefferyleo
jefferyleo

Reputation: 650

Java How to disable the JTable editable when click it

How to disable the cell editing in Jtable???

public class AdminControlPanel extends javax.swing.JFrame

I'm using the JFrame class...so it will automatically inherit the JFrame class... But problem now is I want to disable the cell editing in the JTable...How to do it even I'm not inherit the AbstractTableModel???

Upvotes: 2

Views: 4548

Answers (1)

elbuild
elbuild

Reputation: 4899

If you want to use a custom table model:

//instance table model
DefaultTableModel tableModel = new DefaultTableModel() {

   @Override
   public boolean isCellEditable(int row, int column) {       
       return false; // or a condition at your choice with row and column
   }
};

table.setModel(tableModel);

Or in a quick and dirty way:

table.setEnabled(false);

This second approach is inconsistent with some L&F (it looks grayed out).

Upvotes: 3

Related Questions