简体   繁体   English

从JTable单元获取值

[英]Getting values from JTable cell

I made a column editable in Jtable. 我在Jtable中创建了一个可编辑的列。

I want old values from a cell when I have finished editing a cell 编辑完单元格后,我想从单元格中获取旧值

You can get the value by using 您可以使用获取值

table.getModel().getValueAt(row_index, col_index);

where table is the name of the table and it will return an Object 其中tabletable的名称,它将返回一个Object

Go through this Getting cell value . 完成此获取单元格值 It may be useful for you. 它可能对你有用。

You can use a TableCellListener , like they show here . 您可以像这里显示的那样使用TableCellListener It uses a PropertyChangeEvent to keep track of the old and new values. 它使用PropertyChangeEvent来跟踪旧值和新值。

您还可以创建自己的TableModel实现,并覆盖setValueAt方法以跟踪更改。

Add a TableModelListener to your TableModel. TableModelListener添加到TableModel。 Whenever an event fires you can updated the contents of your text field with the new value in the cell. 每当事件触发时,您都可以使用单元格中的新值更新文本字段的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM