Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erasing whole JTable

Tags:

java

swing

jtable

do you know the best way to erase whole JT ?

like image 963
oneat Avatar asked Nov 25 '25 16:11

oneat


2 Answers

It depends on your model. If you can access it, modify its content, else :

yourJTable.setModel(new DefaultTableModel());
like image 147
Colin Hebert Avatar answered Nov 27 '25 07:11

Colin Hebert


Don't do it like HEBERT suggested, you break the link between your data object and your table model. Bad MVC design.

Ideally, you have access to the data model. Assuming it's a List in the variable myDataList

myDataList.clear();
myTable.getModel().fireTableDataChanged();
like image 28
bluedevil2k Avatar answered Nov 27 '25 06:11

bluedevil2k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!