简体   繁体   中英

JavaFX TreeTableView - center displayed values inside column

在此处输入图片说明

I need to center the values displayed inside columns of a treetableview, how Can i change the position from left to center?

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

You need to set a cellFactory on the TreeTableColumn (as well as the 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 ;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM