java - How to clear contents of a jTable ? -


i have jtable , it's got table model defined this:

javax.swing.table.tablemodel datamodel =       new javax.swing.table.defaulttablemodel(data, columns); tblcompounds.setmodel(datamodel); 

does know how can clear contents ? returns empty table ?

easiest way:

//private tablemodel datamodel; private defaulttablemodel datamodel;   void setmodel() {   vector data = makedata();   vector columns = makecolumns();   datamodel = new defaulttablemodel(data, columns);   table.setmodel(datamodel); }  void reset() {   datamodel.setrowcount(0); } 

i.e. reset method tell model have 0 rows of data model fire appropriate data change events table rebuild itself.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -