Problem getting selected values from checbox in Jtable

0

I go through the whole table obtaining the values of the selected checkboxes the problem is that if it brings all the values except the last one selected:

in this case you should print the values from 3 to 11 but do not print the latter: This is the code that gets jtable values

    String valor = "";
    int cantFilas = tableRamos.getRowCount();
    int i = 0;
    for ( i = 0; i < cantFilas; i++) {

         if (tableRamos.getValueAt(i, 0).equals(true)) {

            valor = tableRamos.getValueAt(i, 1).toString();    //fila seleccionada, y valor guardado en la variable "valor"
            System.out.println(valor);
            //agregarRamos(valor, getaPersist());
         }

    }
    
asked by Sebastian Albornoz 18.10.2017 в 19:22
source

1 answer

0

Remember that the structure of for that you have in your code is the following:

while i is less than cantFilas

for(i = 0; i < cantFilas; i++) {

}

Then everything is fine until i is equal to the number of the last row, so it does not print the last, because it is no less than cantFilas at that time is EQUAL to cantFilas , so that take the last row would be as follows:

While i is less than or equal to cantFilas

for(i = 0; i <= cantFilas; i++) {

    }

Or instead you could add 1 to cantFilas and for would take the last row.

    
answered by 18.10.2017 в 22:42