5

thank you for reading my question.

I'm working with a TreeTableView, and managed to display a Boolean value into one of the columns, by following the results proposed on this answer. It works perfectly, but when applied, the checkbox has a TOP_LEFT alignment, instead of the CENTER one (the CENTER alignment is the default for using checkboxes on regular TableView):

This is the TOP_LEFT alignment I'm having

^ This is the TOP_LEFT alignment I'm having

I searched, but the regular solution for changing the alignment to the content of a cell is not working here, producing no results at all.

Is there any way to change the alignment to CENTER or TOP_CENTER? I'm using Java8.

EDIT WITH MORE INFO The GUI is made in FXML, with the TreeTableView inside a TitledPane. Using this solution to center text cells (same table, other columns) works fine. Removing this from the other columns does not affect the Checkbox column

I tried adding the Checkbox in two different manners, but both of them have the TOP_LEFT alignment:

colUsable.setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(colUsable));

And the other attempt:

colUsable.setCellFactory(new Callback<TreeTableColumn<MyType,Boolean>,TreeTableCell<MyType,Boolean>>() {
    @Override 
    public TreeTableCell<MyType,Boolean> call( TreeTableColumn<MyType,Boolean> p ) {
        return new CheckBoxTreeTableCell<>(); 
    }
});

Thank you so much.

Community
  • 1
  • 1
  • Could you provide a bit more code please? Are you doing things in code or in fxml? And is the table wrapped into another layout container? – aw-think May 26 '15 at 15:29
  • You sure you are not setting the alignment somewhere? – Murat Karagöz May 26 '15 at 15:29
  • Thanks NxDx and Murat K. Just added more info! –  May 26 '15 at 15:38
  • Could you please provide the whole code for CheckBoxTreeTableCell? – aw-think May 26 '15 at 15:57
  • @NwDx It a class is imported from here: javafx.scene.control.cell.CheckBoxTreeTableCell I used that class as explained on the second answer of the first link I provided. –  May 26 '15 at 15:59
  • Do you set this `this.setAlignment(Pos.CENTER);`? In your CheckBoxTreeTableCell? It is inherited from Labeled. I don't know if this really takes care on a checkbox. – aw-think May 26 '15 at 16:06
  • @NxDX I'm not implementing CheckBoxTreeTableCell, so the code is from Java8. You can see the implementation here: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/cell/CheckBoxTreeTableCell.html –  May 26 '15 at 16:12

1 Answers1

5

I got the way to center this. The class CheckBoxTreeTableCell is from Java8 implementation. Check the link to see the documentation. The way I found to change the alignment is this:

colUsable.setCellFactory(new Callback<TreeTableColumn<MyType,Boolean>,TreeTableCell<MyType,Boolean>>() {
    @Override 
    public TreeTableCell<MyType,Boolean> call( TreeTableColumn<MyType,Boolean> p ) {
        CheckBoxTreeTableCell<MyType,Boolean> cell = new CheckBoxTreeTableCell<MyType,Boolean>();
        cell.setAlignment(Pos.CENTER);
        return cell;
    }
});