为什么 setValue 在 Jtable 上不起作用?
我正在java上做项目。
在其中一堂课中,我正在研究 jtable。
现在我正在做的是,
- 表中的数据将从数据库加载。
现在我想更改某些确切行和列的某些值。
因此我使用 jtable 的 setValue 函数。 就像这样......
grayCardTbl.setValueAt(Float.valueOf(String.valueOf(pdiff)),1,4);
我检查了“pdiff”变量,它是完美的。
我总共有 5 列和 10 行。现在行索引和列索引有问题。
之后我还刷新了表格。但它仍然没有反映在桌子上。
I am doing project on java.
In one of the class, I am working on jtable.
Now what i am doing is,
- In the table data will be loaded from the database.
Now i want to change some value at some exact row and column.
so for that i am using jtable's setValue function.
which is like this....
grayCardTbl.setValueAt(Float.valueOf(String.valueOf(pdiff)),1,4);
I have checked the "pdiff" variable, it is perfect.
i had total 5 columns and 10 rows. So now problem with rowindex and column index.
and after this i have also refresh the table. but still it is not reflecting on table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JTable.setValueAt(...)
方法调用TableModel.setValueAt(...)
。我的猜测是您尚未在模型中实现它并且数据没有更新。
编辑:如果您的模型调用
JTable.setValueAt(...)
,它将循环到 stackoverflow。您需要做的是实际更新底层数据。例如,如果您的模型的
getValueAt(...)
确实返回数据[行][列]
,则setValueAt(...)
需要执行数据[行][列] = 值;
The
JTable.setValueAt(...)
method callsTableModel.setValueAt(...)
.My guess is that you've not implemented it in the model and the data doesn't get updated.
Edit: if your model calls
JTable.setValueAt(...)
, it's going to loop into a stackoverflow. What you need to do is actually update the underlying data.For instance if your model's
getValueAt(...)
doesreturn data[row][column]
, thensetValueAt(...)
needs to dodata[row][column] = value;