I have a JTable with two columns and a table model that uses a class which works with a hash map. The elements of this map are the table rows.
Every time I add a new element I need the element to be selected, regardless of any sorting. Now, I've tried using the following method:
int lastRow = table.convertRowIndexToView(tableModel.getRowCount() - 1);
table.setRowSelectionInterval(lastRow, lastRow);
The problem is, this works only when I'm adding data in a sorted fashion (e.g. "A", "B", "C" and not even then since "D", for example, is placed ahead of A once added). Could someone tell me how to solve this problem?