Java:确定用户对自定义模型 JTable 的编辑,以便保存到二进制文件

发布于 2024-09-15 02:29:31 字数 502 浏览 3 评论 0原文

如何获取用户对从二进制文件创建的自定义模型 JTable 的编辑输入,以便将其保存到二进制文件?

我怀疑我的表模型的 getValueAt(int, int) 方法是问题所在,因为它在编辑之前从二进制文件返回数据,而不是特定单元格中的数据。

为了让您了解这意味着什么,

public Object getValueAt(int r, int c) {        
    if (c == 1 ) return data.get(r).getTitle();

变量数据是用 getData 方法中从二进制文件中提取的 ArrayList 初始化的:

List<Data> data = FileOperations.getData();

所以我想我已经确定了问题:确定编辑的单元格包含什么,而不是从二进制文件中提取ArrayList?

我不确定我是否是唯一经历过这个问题的人,但这令人沮丧。

How do I obtain the user's edit input on a custom model JTable created from a binary file in order to save it to the binary file?

I suspect that my table model's getValueAt(int, int) method is the problem because it returns data from the binary file before the edit, not the data in the particular cell.

To give you an idea of what this means,

public Object getValueAt(int r, int c) {        
    if (c == 1 ) return data.get(r).getTitle();

The variable data was initialised with an ArrayList drawn from the binary file in a getData method:

List<Data> data = FileOperations.getData();

So I think I have identified the problem: ascertain what the edited cell contains, rather than what was in the ArrayList drawn from the binary file?

I am not sure if I am the only person to have experienced this problem, but it is frustrating.

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

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

发布评论

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

评论(1

牵强ㄟ 2024-09-22 02:29:31

您需要实现 setValueAt。每次修改单元格时都会调用它。

You need to implement setValueAt. It will be called each time a cell is modified.

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