Get rows from a jtable sorted with RowSorter

166 views Asked by At

Actually i am able to export as excel but it export the entire JTable not the sorted data with Rowsorter, i tried something like but nothing changed :

DefaultTableModel tableModel;
try {
    RowSorter<? extends TableModel> rowSorter = model.getjTable1().getRowSorter();
    TableModel tableModel = rowSorter.getModel();
} catch (NullPointerException ne) {
    tableModel = (DefaultTableModel) model.getjTable1().getModel();

}

A second important thing about my jtable, actually i can select only 1 row and i wont be able to change that.

My question, is, how can i only get the sorted rows from RowSorter ?

Do i need to sort programmatically ? Can i get the visible rows from my jtable ?

1

There are 1 answers

0
camickr On

but it export the entire JTable not the sorted data

The data in the TableModel does NOT change.

Only the data displayed in the JTable (the view) changes.

If you only want the data in the table then you only use methods of the JTable to access the data.

Something like:

for (int row = 0; row < table.getRowCount(); row++)
    for (int column = 0; column < tagle.getColumnCount(); column++)
        System.out.println( table.getValueAt(row, column);