Skip to content

Table's insertRow doesn't work #2137

Description

@PhiLhoSoft

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions