That makes the code lighter. No need for TableColumn this time.
Just a simple call to JTable::updateUI() instead after appending a new row to the grid container:
Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JTable.html#updateUI()
Here’s the new version of “JTable Example” that dynamically appends rows instead of columns:
/**
* JTable Example II (v1.0.2)
* GoToLoop (2019/Jan/01)
* https://Discourse.Processing.org/t/filling-dinamyc-arrays/7049/5
*/
// Imports for creating a frame:
import javax.swing.JFrame;
import javax.swing.JScrollPane;
// Import for creating a table:
import javax.swing.JTable;
// Imports for creating the data grid:
import java.util.Vector;
import static java.util.Arrays.asList;
// Fields for holding the table and its data grid + column titles:
final Vector<Vector<Object>> grid = new Vector<Vector<Object>>();
final Vector<String> titles = new Vector<String>(asList("ID", "TYPE", "VISIBLE"));
final JTable table = new JTable(grid, titles);
void setup() {
looping = false;
// Creates a separate frame to display the table:
final JFrame f = new JFrame();
f.setSize(1200, 600);
f.add(new JScrollPane(table));
f.setVisible(true);
}
void draw() {
background((color) random(#000000));
}
void mousePressed() {
redraw = true;
final Vector<Object> row = new Vector<Object>(titles.size()); // new row.
row.add(frameCount - 2); // "ID"
row.add(platformNames[(int) random(platformNames.length)]); // "TYPE"
row.add(random(1) < .5); // "VISIBLE"
grid.add(row); // appends new row to the data grid.
table.updateUI(); // notifies that the table has changed & needs repainting.
}