更新时间:2023-12-03 11:57:04
我假设(或者这实际上是原因),您实际上遇到了以下行的问题:
I am assuming(or this is actually the reason), You are actually having the issue with the following line:
String oldStatus = String.valueOf(table.getValueAt(rowInModel, 3));
JTable.getValueAt(row, col)
方法将通过将单元格(row, col)
的值转换为 model-index 来返回单元格(row, col)
的值,其中(row, col)
是 view-index .让我们来看看JTable
类的源代码:
JTable.getValueAt(row, col)
method will return the value of the cell (row, col)
by converting them to model-index where (row, col)
is view-index. Let use look into the source of JTable
class:
public Object getValueAt(int row, int column) {
return getModel().getValueAt(convertRowIndexToModel(row),
convertColumnIndexToModel(column));
}
因此,您传递给此函数的(row, col)
应该属于视图而不是模型.在您的上下文中为rowInTable
.从table.convertRowIndexToModel(rowInTable)
获得的rowInModel
已经是模型索引.通过调用JTable.getValueAt(rowInModel, 3)
,您实际上是在尝试将模型索引转换为另一个模型索引,从而导致计算错误.
So your passed (row, col)
to this function should belongs to the view, instead of model. In your context which is rowInTable
. The rowInModel
is already a model index as you got it from table.convertRowIndexToModel(rowInTable)
. By calling JTable.getValueAt(rowInModel, 3)
you are essentially trying to convert a model index to another model index resulting in computational error.