0

I decided it would be easiest to store my data in a custom Row object based on this post

Java data structure to store tabular data

But Im wondering how I actually go onto then create a JTable with this Array of row objects

My current attempt starts out looking like this:

public class TestTable extends JTable {
private final String[] columnNames = {"col1", "col2", "col3"};
    public TestTable() {
    DefaultTableModel model = new DefaultTableModel(columnNames, 10); //10 is just a placeholder for the number of rows as I dont know how to add the data yet
    }
}

My data would be stored in an ArrayList that looks like this:

Row row1 = new Row("1", "2", "3");
ArrayList<String> data = new ArrayList<String>;
data.add(row1);
data.add(row2);
...
data.add(row10);

where my final ArrayList would just look like a list of row objects

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
jquigs62
  • 19
  • 5
  • Instead of a `DefaultTableModel`, try a custom `AbstractTableModel` like [this](https://stackoverflow.com/a/9134371/230513). – trashgod Aug 12 '21 at 21:54

1 Answers1

0
List<String> data = List.of("1", "2", "3" );
model.addRow(data.toArray());

would be a simple approach

g00se
  • 3,207
  • 2
  • 5
  • 9