Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Make JTable cells not editable

 
Cathy Young
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the GUI part of the assignment, I have a FlightTableModel extends AbstractTableModel, which my JTable uses. I am trying to make the table cells uneditable, but failed no matter I override the isCellEditable () or not. I am wondering how to make the cells uneditable. Can anyone help?
Thanks,
Cathy
 
cindy sung
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
By default, cell is not editable. Just remember don't override the 'setValueAt'.
cindy
 
Cathy Young
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by cindy sung:
By default, cell is not editable. Just remember don't override the 'setValueAt'.
cindy[/QB]

Hi Cindy,
I understand that it is not editable by default, so I did not bother to override isCellEditable at first, but it is editable! I did override setValueAt because I need to put the result of search in the table. Do you mean it is editable because I override setValueAt? That really sounds new to me.
Thanks,
Cathy
 
Robin Underwood
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returning false for "isCellEditable" worked for me.
 
Cathy Young
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Robin Underwood:
Returning false for "isCellEditable" worked for me.

Thanks Robin! That is exactly what I am expecting and it does not work for me. I know this sounds silly but could someone tell me what can it possibly be?
Thanks!
 
cindy sung
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cathy:
I did mean that.
Just don't use setValueAt.
You can use any other function with your own name to pass in the value for the table.
cindy
 
Cathy Young
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by cindy sung:
Hi Cathy:
I did mean that.
Just don't use setValueAt.
You can use any other function with your own name to pass in the value for the table.
cindy

Thanks Cindy! I can try that but I still could not understand why they seem to "conflict" with each other.
 
Jeremy Maddera
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to extend the DefaultTableModel and override the isCellEditable(int row, int col);

That should do the trick....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic