title: How to create toolbar with left, center and right sections in javaFX?
body: <p>I'm trying to create a customized toolbar in javafx. This toolbar should be able to display controls in the center, in the left side and in the right side (three sections) of its surface.
  The problem is that I have no idea to achive this. I read many hints related to this problem, but they dont work for me or I'm doing something wrong...</p>
  
  <p>Anyway I wrote several methods, which represent different ways to implement my toolbar but no of them works properly.
  Here you have my attempts:</p>
  
  <ol>
  <li><p>Using HBox Hgrow property as spring. Didn't work.</p>
  
  <pre><code>public ToolBar createToolBar()
  {
      ToolBar toolBar = new ToolBar();
      Pane emptyPane = new Pane();
      HBox spring = new HBox(emptyPane);
      spring.setHgrow(emptyPane, Priority.ALWAYS);
      toolBar.getItems().addAll(spring, new Label("LABEL"));
      return toolBar;
  }
  </code></pre></li>
  </ol>
  
  <p>2.It works for the left and right section, but how to define the center one?</p>
  
  <pre><code>    public AnchorPane createToolBar2()
      {
          AnchorPane toolBar = new AnchorPane();
          Label leftLabel = new Label("left");
          Label rightLabel = new Label("right");
          toolBar.getChildren().addAll(leftLabel, rightLabel);
          toolBar.setLeftAnchor(leftLabel, 0.0);
          toolBar.setRightAnchor(rightLabel, 0.0);
          return toolBar;
      }
  </code></pre>
  
  <ol start="3">
  <li><p>This approach works well for the layout, but I cannot listen for events from left and center section because those are covered by the right section (StackPane is the reason), so this solution is also useless.</p>
  
  <pre><code>public StackPane createToolBar3()
  {
      StackPane toolBar = new StackPane();
      Button left = new Button("left button");
      Button right = new Button("right button");
      Button center = new Button("center button");
      HBox leftSection = new HBox(left);
      leftSection.setAlignment(Pos.CENTER_LEFT);
      HBox centerSection = new HBox(center);
      centerSection.setAlignment(Pos.CENTER);
      HBox rightSection = new HBox(right);
      rightSection.setAlignment(Pos.CENTER_RIGHT);
      toolBar.getChildren().addAll(leftSection, centerSection, rightSection);
  
      left.setOnAction(event -&gt; System.out.println("left"));
      right.setOnAction(event -&gt; System.out.println("right"));
      center.setOnAction(event -&gt; System.out.println("center"));
      return toolBar;
  }
  </code></pre></li>
  </ol>
  
  <p>Above methods I'm invoking in that code block:</p>
  
  <pre><code>   @Override
      public void start(Stage stage) {
  
          BorderPane borderPane = new BorderPane();
          borderPane.setPrefWidth(500);
          borderPane.setPrefHeight(300);
          borderPane.setTop(createToolBar4());
          stage.setScene(new Scene(borderPane));
          stage.show();
      }
  </code></pre>
  
  <p>I will be grateful for any help in that matter.</p>