【问题标题】:JavaFX TreeTableView - center displayed values inside columnJavaFX TreeTableView - 在列内居中显示值
【发布时间】:2015-06-01 10:45:40
【问题描述】:

我需要将显示在 treetableview 列中的值居中,如何将位置从左更改为居中?

final TreeTableColumn<RootMaster, Integer> dataColumn = new TreeTableColumn<>("Data");
dataColumn.setEditable(false);
dataColumn.setMinWidth(300);
dataColumn.setCellValueFactory(new TreeItemPropertyValueFactory<RootMaster, Integer>("bu..."));

【问题讨论】:

    标签: java javafx


    【解决方案1】:

    您需要在TreeTableColumn(以及cellValueFactory)上设置cellFactory

    dataColumn.setCellFactory(col -> {
        TreeTableCell<RootMaster, Integer> cell = new TreeTableCell<RootMaster, Integer>() {
            @Override
            public void updateItem(Integer item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item.toString());
                }
            }
        };
    
        cell.setAlignment(Pos.CENTER);
    
        return cell ;
    });
    

    【讨论】:

    • 非常感谢您抽出宝贵时间回答问题,非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2018-04-26
    • 1970-01-01
    • 2020-07-12
    • 2016-09-26
    • 2019-07-31
    相关资源
    最近更新 更多