[英]Java Swing: How can I get the previous value and the current value when editing a cell in JTable?
You could useTableCellListener to identify when an actual change in the cell data occurs, allowing you to retrieve the current value of the cell (the new value) using tcl.getNewValue()
, as well as the old one using tcl.getOldValue()
.您可以使用TableCellListener来识别单元格数据何时发生实际更改,从而允许您使用
tcl.getNewValue()
检索单元格的当前值(新值),以及使用tcl.getOldValue()
旧值. Additionally, it allows you to get the row
and column
indices of the cell that has been modified.此外,它还允许您获取已修改单元格的
row
和column
索引。
Example as given in the source above:如上面来源中给出的示例:
Action action = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
TableCellListener tcl = (TableCellListener)e.getSource();
System.out.println("Row : " + tcl.getRow());
System.out.println("Column: " + tcl.getColumn());
System.out.println("Old : " + tcl.getOldValue());
System.out.println("New : " + tcl.getNewValue());
}
};
TableCellListener tcl = new TableCellListener(table, action); // where table is the instance of your JTable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.