3

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.

secmask
  • 7,649
  • 5
  • 35
  • 52
  • hmm .. shouldn't happen. Please check if that's specific to JXTable (as opposed to core table). If so, you have detected a bug in JXTable (which you might consider to report in the SwingX issue tracker) A SSCCE demonstrating the problem would help, in all cases – kleopatra Aug 10 '11 at 19:42

1 Answers1

2

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • That object's class is generated by `Thrift` and I'm pretty sure there's an unique value on `id` field to guarantee toString() will show an unique value. – secmask Aug 11 '11 at 01:58
  • Verify that `getColumnClass()` returns `Thrift.class` for its column and that the type of `id` implements `Comparable`. – trashgod Aug 11 '11 at 02:09
  • yep, getColumnClass() return correspond Thrift-class field type, `id` column is typeof `String`. – secmask Aug 11 '11 at 02:23