How to reset a JTable

家住魔仙堡 提交于 2019-12-04 15:34:15

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

model.setRowCount(0);

In order to remove a row from a JTable, you need to remove the target row from the underlying TableModel. If, for instance, your TableModel is an instance of DefaultTableModel, you can remove a row by doing the following:

((DefaultTableModel)myJTable.getModel()).removeRow(rowToRemove);

Updation 2

To know the rows and delete from jtable

 int rows = myJTable.getRowCount();
 for(int i=0;i<rows;i++)
 ((DefaultTableModel)myJTable.getModel()).removeRow(i);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!