Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear JTable

Tags:

java

swing

How can i clear the content of the JTable using Java..

like image 997
Chamal Avatar asked Jan 02 '11 09:01

Chamal


People also ask

How do you clear a JTable row?

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.

What is JTable and how it is created?

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.


1 Answers

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.

like image 159
user85421 Avatar answered Oct 05 '22 02:10

user85421