JavaFX TreeTableView - 列中显示的值

时间:2015-06-01 10:45:41

标签: java javafx

enter image description here

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

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

1 个答案:

答案 0 :(得分:1)

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

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 ;
});