aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
Author

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?


Justin


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
tapanmaru@gmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making all Cells NotEditable in a JTable
 
Similar Threads
Focus traversal problem in JTable
Combobox in JTable
jtable
Tabbing between cells in a JTable
JTable