如何重置JTable [英] How to reset a JTable

查看:244
本文介绍了如何重置JTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JScrollPaneJTable有疑问.

我已经将JTable添加到了JScrollPane,并将JScrollPane添加到了JPanel.当我单击显示"按钮时,JTable将充满数据库中的内容.

I have added a JTable to a JScrollPane, and added the JScrollPane to the JPanel. When I click on 'show' button, the JTable will be filled with contents from the database.

我还有另一个按钮reset,单击该按钮将删除JTableJScrollPane的内容.应该这样做,但是发生的是,即使单击按钮后,JTableJScrollPane的所有内容仍然存在.

I also have another button reset, clicking on which will remove the contents of the JTable, and the JScrollPane. It is supposed to be doing that, but what happens is that, even after clicking the button, all the contents of the JTable and the JScrollPane still exists.

我使用了revalidate()reinstantiate()等,但是没有用.我该如何运作?

I used revalidate(), reinstantiate(), etc, but of no use. How do I make it work?

推荐答案

假设您使用的是DefaultTableModel,则只需执行以下操作:

Assuming you are using a DefaultTableModel, then you just do:

model.setRowCount(0);

这篇关于如何重置JTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆