Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTable, RowSorter, getSelectedRow data

I'm using RowSorter in JTable and when I sort one of the column and call the method getSelectedRowData() it return wrong data.

public Object getSelectedRowData()
{
    if(getDataArray() != null)
    {
        if(grid.getRowSorter() != null)
            return ((GridModel) grid.getRowSorter().getModel()).getData().get(grid.getSelectedRow());
        else
            return model.getData().get(grid.getSelectedRow());
    }
    else
        return null;
}

I think that the problem is that the sorter sort the table data but the ArrayList with data isn't reloaded. How I can fix it?

like image 648
Jordan Borisov Avatar asked May 30 '26 08:05

Jordan Borisov


1 Answers

For getting current selected data you can convert selected row number in view to model row number.

jTable1.convertRowIndexToModel(jTable1.getSelectedRow())
like image 125
JJ Roman Avatar answered May 31 '26 22:05

JJ Roman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!