javaswingarraylistjtabletablerowsorter

how to get specific column's value after using filter


I have used TableRowsorter to filter some rows out from myJtable. Is there a way I can take all the values from a column and store it in arraylist after the filter from the Jtable.


Solution

  • Conceptually, something like this...

    // Apply filter...
    int col = ...; // Column you're interested in
    List values = new ArrayList(table.getRowCount());
    for (int row = 0; row < table.getRowCount(); row++) {
        values.add(table.getValueAt(row, col));
    }
    

    will work.

    Because JTable is a representation of the filtered (and sorted) data, you can just walk through it to get the values it's presenting