How can i clear the content of the JTable using Java..
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.
The JTable class is a part of Java Swing Package and is generally used to display or edit two-dimensional data that is having both rows and columns. It is similar to a spreadsheet. This arranges data in a tabular form. Constructors in JTable: JTable(): A table is created with empty cells.
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 you are using other TableModel, please check the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With