Two Laptop Bag*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Make JTable cells not editable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Make JTable cells not editable" Watch "Make JTable cells not editable" New topic
Author

Make JTable cells not editable

Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
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

Joined: Jul 02, 2002
Posts: 34
Hi,
By default, cell is not editable. Just remember don't override the 'setValueAt'.
cindy


SCJP2; SCJD2;
Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
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

Joined: May 01, 2002
Posts: 117
Returning false for "isCellEditable" worked for me.
Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
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

Joined: Jul 02, 2002
Posts: 34
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

Joined: Mar 02, 2002
Posts: 126
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

Joined: May 02, 2002
Posts: 16
You need to extend the DefaultTableModel and override the isCellEditable(int row, int col);

That should do the trick....
 
Consider Paul's rocket mass heater.
 
subject: Make JTable cells not editable
 
Similar Threads
[JTable] Non editable cells on editable column
stop JTable cells editing
disabling rows in JTable
JTable
Select JTable row, but disable any editing