• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Default Value in JTable

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28174
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic