为什么 setValue 在 Jtable 上不起作用?

发布于 2024-09-01 02:12:31 字数 358 浏览 2 评论 0原文

我正在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅一夜美梦 2024-09-08 02:12:31

JTable.setValueAt(...) 方法调用 TableModel.setValueAt(...)

我的猜测是您尚未在模型中实现它并且数据没有更新。

编辑:如果您的模型调用 JTable.setValueAt(...),它将循环到 stackoverflow。您需要做的是实际更新底层数据。

例如,如果您的模型的 getValueAt(...) 确实返回数据[行][列],则 setValueAt(...) 需要执行数据[行][列] = 值;

The JTable.setValueAt(...) method calls TableModel.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(...) does return data[row][column], then setValueAt(...) needs to do data[row][column] = value;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文