Aurii
asked on
Set JTable non editable
I am using JTable in my application. I want to set all cells of table non-editable. How can I do it? Please help.
ASKER
I am using netbeans. I took JTable 'tblSearch' by drag and drop and done below coding
private String rows[][] = new String[0][5];
private String columns[] = {"Doctor ID","Doctor Name","Address","Contact Number","E-mail Id"};
private javax.swing.table.DefaultT ableModel tm = new javax.swing.table.DefaultT ableModel( rows,colum ns);
tblSearch.setModel(tm);
The code from your example is not working for my code. Please suggest solution for my code.
private String rows[][] = new String[0][5];
private String columns[] = {"Doctor ID","Doctor Name","Address","Contact Number","E-mail Id"};
private javax.swing.table.DefaultT
tblSearch.setModel(tm);
The code from your example is not working for my code. Please suggest solution for my code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you its' worked. But if I need some cell editable and some non editable then how can can I do it?
You need to return true/false for the appropriate cell
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi CEHL, I am not geting how to return true/false for the appropriate cell for my code. I want to set all table non editable except some cells. Please suggest solution for my code.
Hi objects, Actually your code works for single column but what if I want to set it for multiple columns.
Actually my 1 table want all cells non editable except some cells And my another table want all cells non editable except some columns.
Hi objects, Actually your code works for single column but what if I want to set it for multiple columns.
Actually my 1 table want all cells non editable except some cells And my another table want all cells non editable except some columns.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi chej, Actually your code is working for hole row. what if I need to set some cell editable, let's say (2,3) and (5,8)
explained that in my previous comment
you would use
return (mColIndex==2 && rowIndex=3) || (mColIndex==5 && mRowIndex=8);
you would use
return (mColIndex==2 && rowIndex=3) || (mColIndex==5 && mRowIndex=8);
ASKER
but this statement giving me following error,
'operator && cannot be applied to boolean,int'
'operator && cannot be applied to boolean,int'
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)
http://www.exampledepot.com/egs/javax.swing.table/NoEdit.html