不是这样的啊!!是设置 TableModel 增加一个方法,
下面设置第 3列不可编辑
public boolean isCellEditable(int rowindex,int colindex){
if (colindex==2) return false;
.....
return true;
}
下面设置第 3列不可编辑
public boolean isCellEditable(int rowindex,int colindex){
if (colindex==2) return false;
.....
return true;
}
应该如下绑定数据:
//下面假设你有的表格数据使用 String[][] 二维数组格式,表头使用一维数组
aTable.setTableModel(new DefaultTableModel(String[][]{{"12","12"},{"12","12"}},new String[]{"列1","列2"}){
public boolean isCellEditable(int rowindex,int colindex){
if (colindex==1) return false; //设置第二列只读
return true; //其他列可以修改
}
});
//具体,你看看 DefaultTableModel 这个类吧;它还有其他一些构造函数的;如果那些构造函数还不够,你可以自己实现提供数据和表头的方法