• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable How to set editing for a specific column  RSS feed

 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable with 4 columns and I want to only let users the permission to edit only one column and I want also to allow later to edit only specific 1 - few specific cells.
 
Jagan Mohan Reddy
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
override the method isCellEditable(int row,int column) in ur table class.

The code looks something similar to this.

JTable table = new JTable(5,5) {

public boolean isCellEditable(int row,int column) {
if(row ==2 && and column ==3) // specify this depending upon ur requirement. Here the cell 2,3 is not editable.
return false;
else
return true;
}
};
Hope this works out for you..
Regards,
J M Reddy



 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help. Everything works well now.
Originally posted by Jagan Mohan Reddy:
Hi,
override the method isCellEditable(int row,int column) in ur table class.

The code looks something similar to this.

JTable table = new JTable(5,5) {

public boolean isCellEditable(int row,int column) {
if(row ==2 && and column ==3) // specify this depending upon ur requirement. Here the cell 2,3 is not editable.
return false;
else
return true;
}
};
Hope this works out for you..
Regards,
J M Reddy




 
bob morkos
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code and I want to create a dynamic loop the looks for <R> and makes it within the JTable cell un editable. Any idea on how to change my code in order for it to work. Any help would be really appreciated.
<code>
Object tabledata[][] = {
{ "Implementation", "String", "R", "full"},
{ "Mike", "String", "RW", "Object"},
{ "Luc", "String", "R", "Object 1"},
};
String columnheaders[] = { "Name", "Type", "Access", "Value" };
// this code allows me to find the cells which are going to be un editable.
for (i=0; i<3; i++){
if ((tabledata[i][2]) == "R"){
System.out.println( "i :" + i );
System.out.println( tabledata[i][3] );
}
}

table = new JTable(tabledata, columnheaders){
public boolean isCellEditable(int row,int column) {
// problem here on how to add dynamically rows
if ( column == 0 | | column == 1 | | column == 2 [ | | row == i]){ // row ==1 &&
return false;
} else {
return true;
}
}
};
</code>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!