get the last value of a jtable no matter how many rows have java

0

I have the question of how to obtain the data of a cell in the last row of a jtable, I used:

jTable1.getValueAt(1,0).toString();

but only shows me a specific data, I would like to obtain the last value no matter how many data the jtable has.

    
asked by Damii 21.02.2018 в 15:35
source

1 answer

2

There are two ways:

Through the model that handles the data:

TableModel modelo = jtable1.getModel();
int indiceUltimaFila = modelo.getRowCount() - 1;
Object valor = modelo.getValueAt(indiceUltimaFila, 0);

Through the table directly that makes queries to your underlying model:

int indiceUltimaFila = jtable1.getRowCount() - 1;
Object valor = jtable1.getValueAt(indiceUltimaFila, 0);

The difference between one and another is what the user sees in the interface (second option) (for example, if he reordered the columns). vs how they are stored internally (first option) the results may be a little different from what is expected. The above can be seen here

    
answered by 21.02.2018 в 15:53