使用向量编辑 JTable

发布于 2024-07-14 22:03:58 字数 273 浏览 3 评论 0原文

我正在使用 JTable 做一个小型项目。

我使用 Vector 类型作为行值。 例如,public Vector textData = new Vector();。 问题是当我编辑 JTable 中的单元格时,它是可编辑的,但不保留更改后的值。 也就是说,当我在 1 个单元格中输入数据并移至下一个单元格时,以前的数据不会更新。

声明为 Vector 时是否可以编辑单元格?

I'm doing a mini project using JTable.

I used the Vector type for the row values. For example, public Vector textData = new Vector();. The problem is when I edit the cells in the JTable, it is editable but not keeping the changed value. That is, when I enter data in 1 cell and move on to next cell, the previous data is not updated.

Is it possible to edit cells when declared as Vector?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

猫性小仙女 2024-07-21 22:03:58

您使用的模型类型并不重要。 您需要做的基本上是通知您的模型数据在编辑后已更改。 查看如何使用表格获取一些示例。

The type of the model you use does not really matter. What you need to do is basically notify your model that the data has changed after the edit. Check out the How to Use Tables for some examples.

时光暖心i 2024-07-21 22:03:58

也覆盖 setValueAt(Object value, int row, int col) 方法。 它应该存储输入的数据,因此 getValueAt(int row, int col) 方法可以返回新值。 像这样的东西:

private String[][] data;
public Object getValueAt(int row, int col) {
    return data[row][col];
}
public void setValueAt(Object value, int row, int col) {
    data[row][col] = value;
}

Override setValueAt(Object value, int row, int col) method as well. It should store entered data, so getValueAt(int row, int col) method can return new value. Something like this:

private String[][] data;
public Object getValueAt(int row, int col) {
    return data[row][col];
}
public void setValueAt(Object value, int row, int col) {
    data[row][col] = value;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文