• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Default Value in JTable

 
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.


};
 
Marshal
Posts: 25805
69
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.
 
Author
Posts: 974
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.
 
We begin by testing your absorbancy by exposing you to this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic