0

please assist by explaining what this code is trying to do - i mean the logic.

if ((InteractiveForm.this.tableModel.getRowCount() - 1) == row &&//i dont understand this line(the logic)
                    !InteractiveForm.this.tableModel.hasEmptyRow())
                 {
                     InteractiveForm.this.tableModel.addEmptyRow();//this is where we append a new row
                 }

the whole program can be found here

any explanation is greatly appreciated.

2
Contributors
4
Replies
26
Views
2 Years
Discussion Span
Last Post by Nation
Featured Replies
  • Presumably the `row` variable contains a row number in the range 0 to (n-1) where n is the number of rows in a JTable, and `InteractiveForm.this.tableModel` is a reference to the JTable's table model, in which case... `InteractiveForm.this.tableModel.getRowCount()` gives the number of rows, so `InteractiveForm.this.tableModel.getRowCount() -1` is the number of … Read More

1

Presumably the row variable contains a row number in the range 0 to (n-1) where n is the number of rows in a JTable, and InteractiveForm.this.tableModel is a reference to the JTable's table model, in which case...

InteractiveForm.this.tableModel.getRowCount() gives the number of rows, so
InteractiveForm.this.tableModel.getRowCount() -1 is the number of the last row

so that code is testing to see if row refers to the last row in the table

Edited by JamesCherrill

0

Hie James,

Thanks very much for help, now i understand it better.

So this means getRowCount() works the same way length() works in arrays?

I was wondering why do we have to subtract 1.

0

Yes, it's a bit like length() for arrays - just tells you how many rows there are.
You subtract 1 because the rows are numbered 0 to (n-1) (just like elements in an array).
So if there is 1 row, it's number 0. If there are 2 rows they are number 0 and 1. Etc.

Edited by JamesCherrill

0

Hie James,

Thanks very much. My code is working now.
This forum is wonderful.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.