Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Default Value in JTable  RSS feed

 
meera rao
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to disable one column dynamically in the JTable. I am now trying to set the cell with a value and disable it . I am using setValueAt to set the value. but I don't see the value in the cell.


};
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
meera rao
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
meera rao
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for creating a new post. The older post had a different issue ( which was the first part to what I am doing now) I tried to close the post , but I didn't have the permissions.

I thought it would be better to create a new post , since the subject line was misleading.
 
meera rao
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to resolve the issue without using setValueAt to set the value. I appreciate your help, to clear up my mind and think straight to resolve this issue.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!