Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a Jtable in java with 4 columns.I want column 1, column 4 can not edit cell and column 2,column 3 can edit cell.

but I can not do this.

please help me if you know

thanks in advance!
Posted

1 solution

How to JTable - Editors and Renderers[^]

you might want to read that.

You can deal with the TableCellRenderer. But that's fancy.

Much simpler, faster, easier and therefor recommended: This approach[^]

They simply overwrote the function
 public boolean isCellEditable(int rowIndex, int colIndex) {
      return false; //Disallow the editing of any cell
}
in JTable to give the specified allowance.
 
Share this answer
 
Comments
ngthtra 9-Nov-11 20:58pm    
I thought that, but I want to find another way that don't need to override function. If there is not really anyway that better than this way. I must use it
Nagy Vilmos 10-Nov-11 12:34pm    
That is the best way to do it. this is the principle of OO, take what's there and extend, i.e. override, methods that you want to act differently.
TorstenH. 10-Nov-11 13:41pm    
I normally don't use native Components - I always extend them. You can pass additional arguments if you want, in this case e.g. the enabled or disabled columns.

But you can use another approach: when your listener object reacts on the action, you can check whether it's an allowed column or not. But I think that gives a wrong feeling of an editable cell to the user when it is not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900