我在使用此 JTable 时遇到问题。我这样编辑一个单元格
然后我按回车键提交更改。在这里我希望表 gui 刷新新值。
但它们不显示,它们仅在我这样更改选择时显示
fireTableCellUpdated( inRow, inCol );
是当我编辑单元格时在 tableModel
中调用的方法。
我不确定当 fireTableCellUpdated 到 jtable 以重绘和重新验证时,我是否必须向 tableModel 添加监听器。
一些代码:
这在 tableModel 中调用。
@Override
public void setValueAt( Object inValue, int inRow, int inCol ) {
ProductRow productRow = (ProductRow)( getRowsData().get(inRow) );
//more code
productRow.setCantidad( inValue.toString() ); // when this is called all properties are updated from ProductRow
fireTableCellUpdated( inRow, inCol );
}
最佳答案
如果更改特定单元格会更新同一行中的其他单元格(假设这就是您所追求的),则您的 last attempt in your answer使用正确的方法,只是参数不正确:-)
@Override
public void setValueAt( Object inValue, int inRow, int inCol ) {
ProductRow productRow = (ProductRow)( getRowsData().get(inRow) );
// when this is called all properties of productRow are changed.
productRow.setCantidad( inValue.toString() );
// note: both parameters are _row_ coordinates
fireTableRowsUpdated(inRow, inRow);
}
关于java - 编辑单元格时刷新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17676792/