Reputation: 8127
I have a JXTable
in which a model is a List
of distinct objects. There is a problem when I try to map the view index to model index after sorting the view by the selected column header. Using this code,
int[] selecteds = getTableMember().getSelectedRows();
if (selecteds != null && selecteds.length > 0) {
for (int row : selecteds) {
int rr = getTableMember().convertRowIndexToModel(row);
System.out.println(row+":"+rr);
}
}
I get this result:
11:240 12:328 13:1174 14:328 15:1174
I cannot understand why different view indexes map to the same model index?
Solved problem: I called fireTableRowsUpdated right after modify per row so the selected index is not correct anymore.
Upvotes: 3
Views: 1972
Reputation: 205875
Verify that the objects in the List
are in fact distinct. In particular, the Comparator
used by DefaultRowSorter
must be implemented correctly. Note that the default relies on the toString()
method of the underlying objects, but you can specify your own implementation.
Upvotes: 2