To dynamically center an AnchorPane, place it in a StackPane.
To place the AnchorPane
in the top center of the StackPane
, call
StackPane.setAlignment(node, Pos.TOP_CENTER)
AnchorPane anchorPane = new AnchorPane();
...
StackPane stackPane = new StackPane();
stack.getChildren().add(anchorPane);
StackPane.setAlignment(anchorPane, Pos.TOP_CENTER);