Skip to content

Commit 08f1fa5

Browse files
awalter17imagejan
authored andcommitted
Fix insert rows/columns operations
The loops for shifting the rows/columns now loop backwards. This was done because if the loops go forwards it doesn't shift the rows/columns, it instead repeats the column/row following the insert.
1 parent 3e7f248 commit 08f1fa5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/main/java/net/imagej/table/AbstractTable.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public ArrayList<C> insertColumns(final int col, final int count) {
134134
setColumnCount(newColCount);
135135

136136
// copy columns after the inserted range into the new position
137-
for (int oldC = col; oldC < oldColCount; oldC++) {
137+
for (int oldC = oldColCount - 1; oldC >= col; oldC--) {
138138
final int newC = oldC + count;
139139
set(newC, get(oldC));
140140
}
@@ -263,7 +263,9 @@ public void insertRows(final int row, final int count) {
263263
setRowCount(newRowCount);
264264

265265
// copy data after the inserted range into the new position
266-
for (int oldR = row; oldR < oldRowCount; oldR++) {
266+
// NB: This loop goes backwards to prevent the same row from being copied
267+
// over and over again.
268+
for (int oldR = oldRowCount - 1; oldR >= row; oldR--) {
267269
final int newR = oldR + count;
268270
for (int c = 0; c < getColumnCount(); c++) {
269271
set(c, newR, get(c, oldR));

0 commit comments

Comments
 (0)