title: Automatic resize of center node of BorderPane
body: <p>I have an application with a MenuBar, a Toolbar and a TableView.
  Basically, my MenuBar and Toolbar is placed in a VBOX in the top node of a BorderPane, while my TableView is in the center node of the BorderPane.
  My problem is: I would like to hide/show the toolbar and I assume that center node's height will be automatically changed by the layout of the BorderPane.
  I did that in Swing simply by this:
  <code>top.setVisible(false);</code>
  but in JavaFX that seems to not work: center node keep the same size.
  I found a solution but it's disappointing: I change the preferred height of the toolbar. See the code below:</p>
  
  <pre><code>public class Controller
  {
      @FXML
      Pane        pane;
  
      private double height;
  
      @FXML
      public void handleButton()
      {
  //    BAD code: doesn't work
  //      if (pane.isVisible())
  //          pane.setVisible(false);
  //      else
  //          pane.setVisible(true);
  
          if (pane.getPrefHeight() &lt; 1.0)
              pane.setPrefHeight(height);
          else
          {
              height = pane.getPrefHeight();
              pane.setPrefHeight(0.0);
          }
      }
  }
  </code></pre>
  
  <p>and the corresponding FXML document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  &lt;BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="445.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller"&gt;
     &lt;top&gt;
        &lt;VBox prefHeight="134.0" prefWidth="600.0" style="-fx-background-color: gray;"&gt;
           &lt;children&gt;
              &lt;AnchorPane prefWidth="200.0"&gt;
                 &lt;children&gt;
                    &lt;MenuBar AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"&gt;
                      &lt;menus&gt;
                        &lt;Menu mnemonicParsing="false" text="File"&gt;
                          &lt;items&gt;
                            &lt;MenuItem mnemonicParsing="false" text="Close" /&gt;
                          &lt;/items&gt;
                        &lt;/Menu&gt;
                        &lt;Menu mnemonicParsing="false" text="Edit"&gt;
                          &lt;items&gt;
                            &lt;MenuItem mnemonicParsing="false" text="Delete" /&gt;
                          &lt;/items&gt;
                        &lt;/Menu&gt;
                        &lt;Menu mnemonicParsing="false" text="Help"&gt;
                          &lt;items&gt;
                            &lt;MenuItem mnemonicParsing="false" text="About" /&gt;
                          &lt;/items&gt;
                        &lt;/Menu&gt;
                      &lt;/menus&gt;
                    &lt;/MenuBar&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
              &lt;Pane fx:id="pane" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: yellow;" BorderPane.alignment="CENTER" /&gt;
           &lt;/children&gt;
        &lt;/VBox&gt;
     &lt;/top&gt;
     &lt;center&gt;
        &lt;VBox alignment="CENTER" style="-fx-background-color: green;"&gt;
           &lt;children&gt;
              &lt;Button mnemonicParsing="false" onAction="#handleButton" text="Button" /&gt;
           &lt;/children&gt;
        &lt;/VBox&gt;
     &lt;/center&gt;
  &lt;/BorderPane&gt;
  </code></pre>
  
  <p>Is there a more elegant solution than there ?</p>