Hi,
I have to select rows in a jTable in order to manipulate the data. I have the following code:
int [] selected = tblReport.getSelectedRows();
int amount = 0;
for (int i = 0 ; i < selected.length ; i++){
amount += (Integer.parseInt("" + tblReport.getValueAt(i, 6)));
}
txtAmount.setText("" + amount);
txtAmount.setEditable(true);
txtAmount.selectAll();
For some reason it always start counting for row 0, and add the amount of the following rows - according to the number of rows selected, instead of starting from the 1st selected row.
I tested the code with "countSelectedRows()", and as long as the selected rows were consecutive - I got the correct count, however, if I had a non selected row in the middle the count came wrong. I also tested with getSelectedRow() and got the correct index of the 1st selected row, but the amount was always from row 0 of the table down...
Am I using the wrong method?
Thanks