File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JTable" Watch "JTable" New topic


Kris Reid
Ranch Hand

Joined: Jan 05, 2005
Posts: 247
I have 7 colums in a JTable.
I want the first 6 to be uneditable and the last to be editable.

How do you do this with a JTable?

I had to extend it to get the functionality but I'm sure there must ba an easier way.

class MyJTable extends JTable {
MyJTable(String[][] data, String[] columnNames) {
super(data, columnNames);

public boolean isCellEditable(int row, int col) {
if (col < 6) {
return false;
} else {
return true;
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
For that type of behavior you would want to create your own table model. For such a little change you could probably do it in an anonymous inner class that subclasses DefaultTableModel.

If you want more control over the model you can create a subclass of AbstractTableModel, which is not to difficult. The main advantage I see with AbstractTableModel vs DefaultTableModel is picking your own storage. DefaultTableModel uses a Vector, which is fine for most small/medium tables.

Sun has a tutorial on building table models here.
I agree. Here's the link:
subject: JTable
jQuery in Action, 3rd edition