File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Making all Cells NotEditable in a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making all Cells NotEditable in a JTable " Watch "Making all Cells NotEditable in a JTable " New topic

Making all Cells NotEditable in a JTable

Parth Bhatt
Ranch Hand

Joined: Oct 19, 2005
Posts: 58
Hi Guys,

I am working on a Swing App which deals with a JTable. I Have written the following code and it works fine for me, The only problem is that all rows in the table are editable by default. I want to change them to "Not Editable".

Apart from this, the code works absolutely fine for me. So, unless unavoidable, i do not wish to write a custom class inheriting AbstractTableModel.

Can someone suggest a way thru which i could make each cell in the table Not Editable, preferably without writing my own TableModel class ? i.e. is there a method in JTable or DefaultTableModel which will allow me to make each cell not editable...?

Here's my code...

If your new Big Idea doesn't scare the hell out of you, <br />it's probably not a "new Big Idea".
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
if you dont want the JTable editable at all just set the actual
JTable object.setEditable(false);

wouldn't that have the same effect?


You down with OOP? Yeah you know me!
Tapan Maru
Ranch Hand

Joined: May 08, 2006
Posts: 65
which constructor of JTable are you using? I am generally write My own tablemodel class which extends AbstractTableModel class of javax.swing.table package. In that class there is one method you can override:

public boolean isCellEditable(int row, int col) {
return false;

you can override the above method which above implementation so that all cells will be un-editable.

Tapan Maru
I agree. Here's the link:
subject: Making all Cells NotEditable in a JTable
It's not a secret anymore!