0

java JTable, Say I have a huge JTable (800*50) with AbstractTableModel. Now I want to remove all table rows and put new data rows into that table. Which way is easiest and high-performance way to achieve this ?

Thanks.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user595234
  • 6,007
  • 25
  • 77
  • 101
  • Then, we will have too many code changes. Thanks. – user595234 Jan 30 '11 at 17:25
  • I don't understand your comment, because you don't use an AbstractTableModel. You use a model that extends AbstractTableModel. You can easily add a method to your custom model to support a refresh of the model. – camickr Jan 30 '11 at 17:28

1 Answers1

2

The AbstractTableMoeel doesn't support this. If you extend the AbstractTableModel to create a custom model then you need to implement this method yourself.

Or you can use the DefaultTableModel which implements a setRowCount() method. So you can reset the rows to 0. You can then use the insertRow(...) method to add new rows.

However the easier way is to probably just create a new TableModel. Then you can refresh the table by using:

table.setModel( newlyCreatedModel );
camickr
  • 321,443
  • 19
  • 166
  • 288