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.

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

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.

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.

Hie James,

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.