<div dir="ltr">I'm seeing something odd with the alignment of content in a TextFlow and I'm not sure if I'm doing something wrong, or if there is a bug there.<div>The getBaselineOffset() method of the StackPane is returning inconsistent values.  If I sub-class it to force a constant offset, everything works.  Since the StackPane content is always the same, I would expect getBaselineOffset to always return the same value, but in my sample program (below) sometimes it returns 6.5 and other times it returns 14.0. (Tested on macOS 13.2 w. OpenJDK 19/OpenJFX19)</div><div>Parent.getBaselineOffset() is documented as: "Calculates the baseline offset based on the first managed child." - which should always be the same in my example. Sure enough, I checked and getChildren().get(0).getBaselineOffset() is always returning the same value (13.0) - so where is the discrepancy coming from?</div><div><br></div><div>Possibly related to <a href="https://bugs.openjdk.org/browse/JDK-8091236">https://bugs.openjdk.org/browse/JDK-8091236</a></div><div><br></div><div>The following program demonstrates the issue.  While selecting things in the TreeView the TextFlows are repainted with different alignment between the StackPane node and the Text nodes. <br><div><br><font face="monospace">package bugs;<br><br>import javafx.application.Application;<br>import javafx.scene.Scene;<br>import javafx.scene.control.ContentDisplay;<br>import javafx.scene.control.Label;<br>import javafx.scene.control.TreeCell;<br>import javafx.scene.control.TreeItem;<br>import javafx.scene.control.TreeView;<br>import javafx.scene.layout.StackPane;<br>import javafx.scene.layout.VBox;<br>import javafx.scene.paint.Color;<br>import javafx.scene.shape.Circle;<br>import javafx.scene.shape.Polygon;<br>import javafx.scene.text.Text;<br>import javafx.scene.text.TextFlow;<br>import javafx.stage.Stage;<br><br>public class TextFlowWithIcons extends Application {<br>    public static void main(String[] args) {<br>        launch(args);<br>    }<br><br>    @Override<br>    public void start(Stage primaryStage) {<br>        TreeItem<String> node1 = new TreeItem<>("item");<br>        TreeItem<String> node2 = new TreeItem<>("text");<br>        TreeItem<String> node3 = new TreeItem<>("tree");<br>        TreeItem<String> root = new TreeItem<>("ROOT");<br>        root.setExpanded(true);<br>        root.getChildren().addAll(node1, node2, node3);<br>        var treeView = new TreeView<String>(root);<br>        treeView.setCellFactory(this::cellFactory);<br>        VBox box = new VBox(8, new Label("Fiddle with the TreeView...\nWatch the alignment bounce around."), treeView);<br>        var scene = new Scene(box);<br>        primaryStage.setScene(scene);<br>        primaryStage.setTitle("Graphic Alignment Issue");<br>        primaryStage.show();<br>    }<br><br>    private TreeCell<String> cellFactory(TreeView<String> tv) {<br>        return new CustomCell();<br>    }<br><br>    private static class CustomCell extends TreeCell<String> {<br><br>        public CustomCell() {<br>            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);<br>        }<br><br>        @Override<br>        protected void updateItem(String item, boolean empty) {<br>            super.updateItem(item, empty);<br>            if (item != null && !empty) {<br>                var text1 = new Text("Some ");<br>                var text2 = new Text("colored ");<br>                var text3 = new Text(item);<br>                text2.setFill(Color.GREEN);<br>                var circle = new Circle(6);<br>                circle.setStroke(Color.BLACK);<br>                circle.setFill(Color.RED);<br>                var triangle = new Polygon(-6, 6, 6, 6, 0, -6);<br>                triangle.setFill(Color.YELLOW);<br>                triangle.setStroke(Color.BLACK);<br>                triangle.setScaleX(0.5);<br>                triangle.setScaleY(0.5);<br>                triangle.setTranslateX(4);<br>                triangle.setTranslateY(4);<br>                var icon = new StackPane(circle, triangle)</font></div><div><font face="monospace">// uncomment to fix</font></div><div><font face="monospace">//                {<br>//                    @Override<br>//                    public double getBaselineOffset() {<br>//                        return 12;<br>//                    }<br>//                }<br></font></div><div><font face="monospace">                ;<br>                var textFlow = new TextFlow(icon, text1, text2, text3);<br>                setGraphic(textFlow);<br>            } else {<br>                setGraphic(null);<br>            }<br>            setText(null);<br>        }<br><br>    }<br>}</font><br></div></div><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">Regards,</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Scott</font></div><div><font face="arial, sans-serif"><br></font></div></div>