不曾碰到这样的问题.....试试修改值后把编辑的单元结束编辑。 if (table.getCellEditor() != null) { table.getCellEditor().stopCellEditing(); }
"不曾碰到这样的问题....."?!为什么我每次用setValueAt()之后整列都不能写了,不论我是用DefaultTableModel还是重写的DefaultTableModel? 我还是把重写后的类贴上来,大家看看是哪里的问题:public class NoEditableTableModel extends DefaultTableModel { private Vector v = new Vector(); private int mul = 1;
public NoEditableTableModel(int r, int c, Vector v, int tableNr) { super(r, c); this.v = v; this.mul = tableNr; }
public boolean isCellEditable(int row, int col) { int index = v.indexOf(""); if (index != -1){ if (mul == 1){ if (row == mul*index) return false; else return true; }else{ if (row >= mul*index && row <= mul*index + 2) return false; else return true; } }else return true; } }在里面我设置其中的几行在特殊情况下不可编辑,但在我看来这并不影响setValueAt()!难道我要再重写setValueAt()?如果是,应该怎么写呢?重申一下我的目的 -- 在使用JTable.setValueAt(object, row, col)后,还能使所编辑列(column)保持可编辑状态。
if (table.getCellEditor() != null) {
table.getCellEditor().stopCellEditing();
}
private Vector v = new Vector();
private int mul = 1;
public NoEditableTableModel(int r, int c,
Vector v, int tableNr) {
super(r, c);
this.v = v;
this.mul = tableNr;
}
public boolean isCellEditable(int row, int col) {
int index = v.indexOf("");
if (index != -1){
if (mul == 1){
if (row == mul*index)
return false;
else return true;
}else{
if (row >= mul*index && row <= mul*index + 2)
return false;
else return true;
}
}else return true;
}
}在里面我设置其中的几行在特殊情况下不可编辑,但在我看来这并不影响setValueAt()!难道我要再重写setValueAt()?如果是,应该怎么写呢?重申一下我的目的 -- 在使用JTable.setValueAt(object, row, col)后,还能使所编辑列(column)保持可编辑状态。
还是要靠自己!不过这种自问自答的方式也不错^^有兴趣要分的朋友可以顶一下。