usertest
usertest

Reputation: 2262

JavaFX TreeTableView - center displayed values inside column

enter image description here

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..."));

Upvotes: 0

Views: 389

Answers (1)

James_D
James_D

Reputation: 209330

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

Upvotes: 1

Related Questions