对于你的情况,你可以尝试这样的事情:
table.sortPolicyProperty().set(t -> {
Comparator comparator = (r1, r2)
-> r1 == rowTotal ? 1 //rowTotal at the bottom
: r2 == rowTotal ? -1 //rowTotal at the bottom
: t.getComparator() == null ? 0 //no column sorted: don't change order
: t.getComparator().compare(r1, r2); //columns are sorted: sort accordingly
FXCollections.sort(table.getItems(), comparator);
return true;
});
如果你不明白这里发生了什么,快照 without lambda expression :
table.sortPolicyProperty().set( new Callback, Boolean>() {
@Override
public Boolean call(TableView param) {
Comparator comparator = new Comparator() {
@Override
public int compare(SalesInvoiceNetSale r1, SalesInvoiceNetSale r2) {
if (r1 == rowTotal) {
return 1;
} else if (r2 == rowTotal) {
return -1;
} else if (param.getComparator() == null) {
return 0;
} else {
return param.getComparator().compare(r1, r2);
}
}
};
FXCollections.sort(table.getItems(), comparator);
return true;
}
});