0

You can create a table model and add it to a table

TableModel tm = new TableModel();
JTable table = new JTable(tm);

however, if I init a Table

JTable table = new JTable();

and then create a table model later on...

TableModel tm = new TableModel();
tm.addValueAt(...);
...

Is there a way I can add this table model to the original table?

I've actually created my own classes to extend TableModel and JTable, and I thought that I could simply reconstruct the table given the new table model, but this doesn't seem to work.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Jonathan Viccary
  • 722
  • 1
  • 9
  • 27

1 Answers1

6

As stated here: JTable, You can use setModel(TableModel)

public void setModel(TableModel dataModel)

Sets the data model for this table to newModel and registers with it for listener notifications from the new data model.

Harry Joy
  • 58,650
  • 30
  • 162
  • 207