I don't know what you meant to do with that code. What your code actually does is this:
When something asks whether a cell in column 3 is editable or not, the code then sets the value of that cell to something.
I wouldn't set the value of a cell only when something wanted to know whether the cell was editable. That probably doesn't happen until the user tries to change the displayed value. I would take that call to setValue() and put it somewhere else. Perhaps in the initialization of the table, if that would be appropriate, but it's impossible to tell from what you said. [ July 11, 2007: Message edited by: Paul Clapham ]
posted 13 years ago
I have a JTable with n rows and I am trying to set a value to one of the column ( say column 3 ) and disable that column so that the user cannot change it.
First, let me point out that it wasn't polite to start a new thread for this instead of continuing the old one.
Second, I would have to agree that calling setValueAt() from within isCellEditable() is almost surely a bad idea.
Originally posted by meera rao: I have a JTable with n rows and I am trying to set a value to one of the column ( say column 3 ) and disable that column so that the user cannot change it.
Having isCellEditable() return false will make it so the user cannot change it.
As for "set a value to one of the column" there are many ways to do this. One is to call setValueAt(), but only once for each row. Better, I think, would be to use a custom cell renderer for that column. Your renderer would be free to ignore the actual value stored in the table model and draw anything it wants.