title: JavaFX center Button in VBox
body: <p>I fail to center a Button in a VBox in Java code!
  I used Scene Builder to create a SplitPane with the left AnchorPane having a Button centered in a VBox. 
  I want to recreate this, a Button in a VBox, in the right AnchorPane but not in FXML, in Java Code. But the right Button does not center, although I use <code>vb.setAlignment(Pos.CENTER);</code> :</p>
  
  <p><a href="https://i.stack.imgur.com/6NUpC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6NUpC.png" alt="enter image description here"></a></p>
  
  <p>My FXML code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.SplitPane?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.layout.VBox?&gt;
  
  &lt;AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="testimageview.MainViewController"&gt;
     &lt;children&gt;
        &lt;SplitPane dividerPositions="0.5" prefHeight="200.0" prefWidth="400.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
          &lt;items&gt;
            &lt;AnchorPane fx:id="leftAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"&gt;
                 &lt;children&gt;
                    &lt;VBox alignment="CENTER" prefHeight="198.0" prefWidth="171.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
                       &lt;children&gt;
                          &lt;Button mnemonicParsing="false" text="FXML" /&gt;
                       &lt;/children&gt;
                    &lt;/VBox&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
            &lt;AnchorPane fx:id="rightAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" /&gt;
          &lt;/items&gt;
        &lt;/SplitPane&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>And my Java Controller class code:</p>
  
  <pre><code>package testimageview;
  
  import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.geometry.Pos;
  import javafx.scene.control.Button;
  import javafx.scene.layout.AnchorPane;
  import javafx.scene.layout.Priority;
  import javafx.scene.layout.VBox;
  
  public class MainViewController implements Initializable {
  
      @FXML
      private AnchorPane leftAnchorPane;
  
      @FXML
      private AnchorPane rightAnchorPane;
  
      public MainViewController() {
      }
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
      VBox.setVgrow(leftAnchorPane, Priority.ALWAYS);
  
      VBox vb = new VBox();
  
      Button rightButton = new Button();
      rightButton.setText("Java");
  
      vb.setAlignment(Pos.CENTER);
      vb.getChildren().addAll(rightButton);
  
      rightAnchorPane.getChildren().add(vb);
  
      } 
  }
  </code></pre>