title: Can I change the alignment of one element in a VBox?
body: <p>If I put controls (or layouts with controls) in a VBox all elements get aligned the same way.  I want to change the alignment of one of those elements like this</p>
  
  <p><a href="https://i.stack.imgur.com/mQq71.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mQq71.png" alt="VBox Alignment Demo"></a></p>
  
  <p>I tried to change the alignment of <code>Button 2</code>by calling <code>setAlignment()</code> on it, but calling <code>setAlignment()</code> on an individual element doesn't change the alignment within the VBox.  (The JavaDoc's explanation of Button.setAlignment() is useless.)</p>
  
  <p>I was able to change the alignment of <code>Button 4</code> by using an HBox and setting its alignment.  I'd rather not introduce extra Nodes if I don't have to.  Is there a way to change the alignment of one Node in a layout container without having to use another layout?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>    public class VBoxAlignmentDemoApplication extends Application {
  
      public static void main(String[] args) {
          launch(args);
      }
  
  
      @Override
      public void start(Stage primaryStage) throws Exception {
  
          FXMLLoader loader = new FXMLLoader(getClass().getResource("/VBoxAlignmentDemo.fxml"));
          Parent root = loader.load();
  
          Scene scene = new Scene(root);
          primaryStage.setScene(scene);
          primaryStage.setTitle("VBoxAlignmentDemo");
          primaryStage.show();
      }
  }
  
  public class VBoxAlignmentDemoController implements Initializable {
  
      @FXML
      VBox vbox;
  
      @FXML
      Button button2;
  
      public void initialize(URL arg0, ResourceBundle arg1) {
          button2.setAlignment(Pos.CENTER_RIGHT);
      }
  }
  
  &lt;VBox fx:id="vbox" alignment="CENTER_LEFT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="vbox.alignment.demo.VBoxAlignmentDemoController"&gt;
     &lt;children&gt;
        &lt;Button mnemonicParsing="false" text="Button 1" /&gt;
        &lt;Button fx:id="button2" mnemonicParsing="false" text="Button 2" /&gt;
        &lt;Button mnemonicParsing="false" text="Button 3" /&gt;
        &lt;HBox alignment="CENTER"&gt;
           &lt;children&gt;
              &lt;Button mnemonicParsing="false" text="Button 4" /&gt;
           &lt;/children&gt;
        &lt;/HBox&gt;
     &lt;/children&gt;
  &lt;/VBox&gt;
  </code></pre>