Java 从 JTable 单元格获取值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16395939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting values from JTable cell
提问by user2042166
I made a column editable in Jtable.
我在 Jtable 中创建了一个可编辑的列。
I want old values from a cell when I have finished editing a cell
当我完成一个单元格的编辑后,我想要一个单元格的旧值
回答by Maximin
You can get the value by using
您可以通过使用获得价值
table.getModel().getValueAt(row_index, col_index);
table.getModel().getValueAt(row_index, col_index);
where table
is the name of the table and it will return an Object
table
表的名称在哪里,它将返回一个Object
Go through this Getting cell value. It may be useful for you.
通过这个获取单元格值。它可能对你有用。
回答by Catalina Island
You can use a TableCellListener
, like they show here. It uses a PropertyChangeEvent
to keep track of the old and new values.
您可以使用TableCellListener
,就像他们在此处显示的那样。它使用 aPropertyChangeEvent
来跟踪旧值和新值。
回答by P. Lalonde
You also could create your own implementation of a TableModel and override the setValueAt method to keep track of the changes.
您还可以创建自己的 TableModel 实现并覆盖 setValueAt 方法以跟踪更改。
回答by camickr
Add a TableModelListener
to your TableModel. Whenever an event fires you can updated the contents of your text field with the new value in the cell.
将 a 添加TableModelListener
到您的 TableModel。每当事件触发时,您都可以使用单元格中的新值更新文本字段的内容。