JavaFX TableView Sort Policy

后端 未结 2 746
北荒
北荒 2021-01-13 03:33

I have a tableview which has an observable list of custom class objects attached to it (Class type: SalesInvoiceNetSale). The data all displays fine within the table. The la

2条回答
  •  旧时难觅i
    2021-01-13 04:29

    Here is the code to do the same thing with a TreeTableView in Java8 and lambda expressions.

    treeTable.sortPolicyProperty().set(treeTableView -> {
        Comparator> comparator = (model1, model2) -> {
    
            if(model1.isTotalRow()) {
                return 1;
            } else if(model2.isTotalRow()) {
                return -1;
            } else if (treeTableView.getComparator() == null) {
                return 0;
            } else {
                return treeTableView.getComparator().compare(model1, model2);
            }
        };
    
        treeTable.getRoot().getChildren().sort(comparator);
    
        return true;
    });
    

提交回复
热议问题