如何清除扩展 AbstractTableModel 的自定义 TableModel

发布于 2024-10-20 06:27:40 字数 116 浏览 10 评论 0原文

正是问题所指出的。我创建了一个自定义 tableModel 类,我想在 actionPerformed 上清除与该模型关联的 JTable

Exactly what the question states. I created a custom tableModel class and I want to clear the JTable associated with that model on an actionPerformed.

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

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

发布评论

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

评论(1

神经大条 2024-10-27 06:27:40

您必须从用于表的 TableModel 中删除数据。

如果使用 DefaultTableModel,只需将行计数设置为零。这将删除行并触发 TableModelEvent 来更新 GUI。

JTable table;

…
DefaultTableModel model = (DefaultTableModel) table.getModel();

model.setRowCount(0);

如果使用其他 TableModel 请查看文档。

You must remove the data from the TableModel used for the table.

If using the DefaultTableModel, just set the row count to zero. This will delete the rows and fire the TableModelEvent to update the GUI.

JTable table;

…
DefaultTableModel model = (DefaultTableModel) table.getModel();

model.setRowCount(0);

If using other TableModel please check the documentation.

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