• Post Reply Bookmark Topic Watch Topic
  • New Topic

making cells in one column editable  RSS feed

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I am writing a program with a JTable with 4 columns. I would like to have only the cells in zero index column editable. I have a simple TableModel but it makes the cells in all columns editable. Would anyone with experience in JTabels be of any assistance. I have search the internet without much success. Thank you.

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a TableModel implementation that implements the isCellEditable method so that it only returns true for columnIndex 0.
 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your suggestion. I have modified the code and it works.

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Less code is better, in my opinion. Your code will certainly work. But try a shorter but equivalent version:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!