Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable cell uneditable  RSS feed

 
sabbir kazi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to make a (or all) JTable cell uneditable? So that when user click on it - it will be only highlighted, not turning into editing mode.
Thanks.
Sabbir
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at DefaultTableModel or AbstractTableModel isCellEditable(). Just create your table model using one of these and change the isCellEditable() method to return false for the cells, rows or columns that you want non-editable.
 
sabbir kazi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul for your reply.
I understand that the isCellEditable(row, col) method only return the boolean value to indicate whether the given cell is editable or not.
My question is how to make a particular cell or all cells in a JTable uneditable?
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just like I told you. If you return false, you can't edit the cell.
 
sabbir kazi
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. I understand what you mean.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't, let me know.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!