TableViewPlus.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:blackmarket 作者:
/**
 * Just add some sample data in the constructor.
 */
public TableViewPlus(Map<String, String> columnNameFieldMapping, 
        double[] minWidths, 
        ObservableList<S> masterData) {

    // remove focus
    setStyle(
            "-fx-background-color: -fx-outer-border, -fx-inner-border, -fx-body-color; -fx-background-insets: 0, 1, 2; -fx-background-radius: 5, 4, 3;");

    // 0. Initialize the columns.
    columnNameFieldMapping.entrySet().stream().forEachOrdered(entry -> {
        TableColumn<S, String> column = new TableColumn<>(entry.getKey());
        column.setCellValueFactory(new PropertyValueFactory<S, String>(entry.getValue()));
        column.impl_setReorderable(false);
        getColumns().add(column);
    });

    IntStream.range(0, getColumns().size())
        .forEach(i -> getColumns().get(i).setMinWidth(minWidths[i]));

    // 1. Wrap the ObservableList in a FilteredList (initially display all data).
    filteredData = new FilteredList<>(masterData, p -> true);

    // 3. Wrap the FilteredList in a SortedList. 
    SortedList<S> sortedData = new SortedList<>(filteredData);

    // 4. Bind the SortedList comparator to the TableView comparator.
    sortedData.comparatorProperty().bind(comparatorProperty());

    // 5. Add sorted (and filtered) data to the table.
    setItems(sortedData);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号