Reference: http://forum.processing.org/two/discussion/250/using-insertrow-with-a-table
Processing 2.0
Example code:
Table table;
void setup() {
table = new Table();
table.addColumn("species", Table.STRING);
table.addColumn("name", Table.STRING);
TableRow a = table.addRow();
a.setString("species", "A");
a.setString("name", "a");
String[] c = { "C", "c" };
table.addRow(c);
println(table);
table.save(System.out, "csv");
String[] b = { "B", "b" };
table.insertRow(0, b);
}
Result: ArrayIndexOutOfBoundsException
Why?
Line
System.arraycopy(columns[col], insert, stringTemp, insert+1, (rowCount - insert) + 1);
(and related) seems wrong. I think it should be:
System.arraycopy(columns[col], insert, stringTemp, insert+1, rowCount - insert);
With 2 rows and inserting at pos 1, we want to copy 1 item after the insertion position.
Reference: http://forum.processing.org/two/discussion/250/using-insertrow-with-a-table
Processing 2.0
Example code:
Result: ArrayIndexOutOfBoundsException
Why?
Line
System.arraycopy(columns[col], insert, stringTemp, insert+1, (rowCount - insert) + 1);
(and related) seems wrong. I think it should be:
System.arraycopy(columns[col], insert, stringTemp, insert+1, rowCount - insert);
With 2 rows and inserting at pos 1, we want to copy 1 item after the insertion position.