//package bugs; import javafx.application.Application; import javafx.geometry.VPos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; public class JDK8089789_Center extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Center Text"); primaryStage.setWidth(250); primaryStage.setHeight(250); Group root = new Group(); Scene scene = new Scene(root); Text text = new Text(); // text.setFont(new Font("Arial BOLD", 14)); // text.setText("Center Text"); text.layoutXProperty(). bind(scene.widthProperty().subtract(text.layoutBoundsProperty().get(). getWidth()).divide(2)); text.layoutYProperty(). bind(scene.heightProperty().subtract(text.layoutBoundsProperty().get(). getHeight()).divide(2)); text.setTextOrigin(VPos.TOP); // Bug: Comment out the following two lines when uncommenting the previous commented-out lines. text.setFont(new Font("Arial BOLD", 14)); text.setText("Center Text"); root.getChildren().add(text); primaryStage.setScene(scene); primaryStage.show(); text.layoutXProperty().addListener((observable, oldValue, newValue) -> { System.out.println(text.layoutXProperty()); System.out.println("oldValue = " + oldValue + ", newValue = " + newValue); System.out.println("width = " + text.layoutBoundsProperty().get().getWidth()); System.out.println(); }); text.layoutYProperty().addListener((observable, oldValue, newValue) -> { System.out.println(text.layoutYProperty()); System.out.println("oldValue = " + oldValue + ", newValue = " + newValue); System.out.println("height = " + text.layoutBoundsProperty().get().getHeight()); System.out.println(); }); } }