import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.Background;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class TreeTableBug extends Application {
    public static void main(String[] args) {
        TreeTableBug.launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        TreeTableView<ItemPayload> table = new TreeTableView<>();

        TreeTableColumn<ItemPayload, String> col1 = new TreeTableColumn<>("name");
        col1.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getValue().name));

        TreeTableColumn<ItemPayload, String> col2 = new TreeTableColumn<>("some data");
        col2.setCellValueFactory(v -> new SimpleStringProperty(v.getValue().getValue().someData));
        col2.setCellFactory(c -> new TreeTableCell<>() {
            private Label customLabel = new Label();

            {
                customLabel.setBackground(Background.fill(Color.YELLOW));
            }

            @Override
            protected void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setGraphic(null);
                } else {
                    this.customLabel.setText(item != null ? item : "none");
                    this.setGraphic(this.customLabel);
                }
            }
        });

        table.getColumns().addAll(col1, col2);

        TreeItem<ItemPayload> rootItem = new TreeItem<>(new ItemPayload("root", "root value"));
        rootItem.setExpanded(true);
        rootItem.getChildren().addAll(
            new TreeItem<>(new ItemPayload("A", null)),
            new TreeItem<>(new ItemPayload("B", null))
        );
        table.setRoot(rootItem);

        StackPane root = new StackPane();
        root.getChildren().add(table);
        primaryStage.setScene(new Scene(root, 500, 500));
        primaryStage.show();
    }

    record ItemPayload(String name, String someData) {}
} 