如何重置JTable [英] How to reset a JTable
问题描述
我对JScrollPane
和JTable
有疑问.
我已经将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
,单击该按钮将删除JTable
和JScrollPane
的内容.应该这样做,但是发生的是,即使单击按钮后,JTable
和JScrollPane
的所有内容仍然存在.
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屋!