JTable question

Is there a way to make rows in a JTable selectable but not editable?I want a user to be able to select a row but not be able to edit anything in the table. How do I do this?TIA,Jennifer
[213 byte] By [jmc95825a] at [2007-11-27 2:31:02]
# 1
Read JTable javadocs - isCellEditable.
kirillga at 2007-7-12 2:45:28 > top of Java-index,Desktop,Core GUI APIs...
# 2

How does this reply answer my question?

isCellEditable will tell me whether or not a cell is editable. I don't care if it is. I want to make the entire table not editable.

If I don't enable the table then the user will not be able to select a row. I want the user to be able to select a row but not be able to any cells in the table.

jmc95825a at 2007-7-12 2:45:28 > top of Java-index,Desktop,Core GUI APIs...
# 3

redifine the model of your table in this way. However, reading the API you may understand many things.

DefaultTableModel model = new DefaultTableModel(contenuto, header) {

public boolean isCellEditable (int row, int col) {

return false;

}

};

table.setModel(model);

}

albertthea at 2007-7-12 2:45:28 > top of Java-index,Desktop,Core GUI APIs...
# 4

Ok, so if I want to make the table editable for some users I would have to check who the user is first and return either true or false from isCellEditable? Is this the best way to do it? It seems to add a layer of complication in my table model (which is a custom table model).

Thank you though for your more comprehensive reply.

jmc95825a at 2007-7-12 2:45:28 > top of Java-index,Desktop,Core GUI APIs...
# 5

> Ok, so if I want to make the table editable for some

> users I would have to check who the user is first and

> return either true or false from isCellEditable? Is

> this the best way to do it? It seems to add a layer

> of complication in my table model (which is a custom

> table model).

> Thank you though for your more comprehensive reply.

yes, you should do in the way you explained!

albertthea at 2007-7-12 2:45:28 > top of Java-index,Desktop,Core GUI APIs...
# 6

> It seems to add a layer of complication in my table model...

I always override the isCellEditable(...) method of JTable. I believe the TableModel should be for storing data.

The table is used for the view of the data. I believe being editable or not is a function of the view not on how the data is stored.

camickra at 2007-7-12 2:45:28 > top of Java-index,Desktop,Core GUI APIs...