I have a JTable with a model instantiated as:
TableModel ss = new DefaultTableModel(myArray[][], myHeaderArray[]);
Where the arrays are generated. However, at the moment, you can still edit cells. How can I prevent this?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Extend JTable or the DefaultTableModel, override the
isCellEditable(int row, int column)method, and return false for the cells that you don’t want the user to be able to edit.For instance, if you didn’t want the user to be able to modify the 2nd column, then you’d do something like:
Note as per mre’s comment that the above method could be compressed and re-written as:
If you don’t want the user to be able to edit any cells, then simply have this method return false always: