# Filling Dinamyc Arrays\[\]\[\]

**URL:** <https://discourse.processing.org/t/filling-dinamyc-arrays/7049>\
**Category:** Coding Questions\
**Created:** [December 31, 2018, 8:46am UTC](https://discourse.processing.org/t/filling-dinamyc-arrays/7049 "2018-12-31T08:46:30Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 2, 2019, 1:00am UTC](https://discourse.processing.org/t/filling-dinamyc-arrays/7049/5 "2019-01-02T01:00:09Z")

</div>

That makes the code lighter. No need for [TableColumn](http://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/table/TableColumn.html#%3Cinit%3E(int)) 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()](http://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: 😉

```java
/**
 * 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.
}

```

---

_[View the full topic](https://discourse.processing.org/t/filling-dinamyc-arrays/7049)._
