Search code examples
javaswingsortingjtabletablerowsorter

Setting SortKey of JTable with duplicate values does not work


I have a problem with setting SortKeys in java. I used a SortKey from an existing JTable and set it to another one, but somehow it is not working when there are duplicate values in a column, for example the values 1, 2, 3, 4, 5 are sorted correctly, but the values 1, 1, 1, 2, 2, 2, 3, 3 differ in the their order in the JTable.

PS: I already have setMaxSortKeys(int max) on 1.


Solution

  • It is possible that initial ordering of the rows is different in two tables. It is also possible that the sorting algorithm used to sort the tables is not stable. In these cases you can't expect the order to be same for duplicate column values.