I think I have found a bug/regression with Java 11 regarding TreeTableView.
This has worked fine on JavaFX 8, but is messed up with JavaFX 11.
1) The arrow button is on the text
2) No text indentation levels: Each row (no matter the level) is at the
left edge of the TreeTableView.

I can file an issue at GitHub if this is a real bug/regression. I just
wanted to check first here.

TreeTableColumn<OurDataObject, Label> column = new
TreeTableColumn<>("Column");
column.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(new
OurDataObjectLabel(param.getValue().getValue())));

We are using Label here so we can set StyleClass based on some information
in the OurDataObject.

class OurDataObject {
    private String name;
    public String getName() { return name; }
}

class AlsoOurDataObject extends OurDataObject {
    public boolean isSomething() { ... }
}

class OurDataObjectLabel extends Label() {
    public OurDataObjectLabel(OurDataObject ourDataObject) {
        setText(ourDataObject.getName());
        if (ourDataObject instanceof AlsoOurDataObject) {
            if (((AlsoOurDataObject) ourDataObject).isSomething()) {
                getStyleClass().add("style");
            }
        }
    }
}

A workaround was to use OurDataObject for both types in the
TreeTableColumn, create a CellFactory to do what has been done in
OurDataObjectLabel and in addition to the CellValueFactory.

Code Example for reproducing the problem:
This is using a String instead of an Object as the data model for
simplicity.
I have attached a screenshot that illustrates this problem. Made with the
example code below.

import javafx.application.Application;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class App extends Application {

    public static void main(String[] args) {
        App.launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        StackPane root = new StackPane();

        TreeTableView<String> treeTableView = new TreeTableView<>();
        treeTableView.setShowRoot(false);
        root.getChildren().add(treeTableView);

        TreeTableColumn<String, Text> column = new
TreeTableColumn<>("Column");
        column.setPrefWidth(200);
        treeTableView.getColumns().add(column);

        column.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(
                new Text(param.getValue().getValue())));

        TreeItem<String> rootItem = new TreeItem<>("");
        treeTableView.setRoot(rootItem);

        TreeItem<String> item1 = new TreeItem<>("LEVEL1");
        item1.setExpanded(true);
        rootItem.getChildren().add(item1);

        TreeItem<String> item2 = new TreeItem<>("LEVEL2");
        item2.setExpanded(true);
        item1.getChildren().add(item2);

        TreeItem<String> item3 = new TreeItem<>("LEVEL2_1");
        item3.setExpanded(true);
        item2.getChildren().add(item3);

        Scene scene = new Scene(root, 250, 150);

        stage.setTitle("JavaFX11");
        stage.setScene(scene);
        stage.show();
    }
}


/Sverre

Reply via email to