title: JavaFX: Dynamically added VBox does not show up
body: <p>I'm working on a project that requires a "tabled" representation of VBoxes. My hierarchical layout of the application is GridPane -> VBox (in one of the Cells) -> VBoxes (that display different datasets on top of each other) -> Data. I have two Scenes.</p>
  
  <p>Data is displayed on Scene 1. The user can add data through a form and by clicking a button on Scene 2. Then, the added data should be displayed below the existing data as a VBox within the parent-VBox on Scene 1 again.</p>
  
  <p>Here is the code that will make it clear:</p>
  
  <p>My Scene 1 .fxml file looks the following (Simplified):</p>
  
  <pre><code>&lt;GridPane fx:id="grid" fx:controller="application.Controller"&gt;
    [here: ColumnConstraints]
    &lt;children&gt;
      &lt;VBox fx:id="parentBox" GridPane.columnIndex="0" GridPane.rowIndex="1"/&gt;
      &lt;Button fx:id="goToScene2" text="+" onAction="#goToScene2"/&gt; 
    &lt;/children&gt;  
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>Scene 2 just has a button and a TextField:</p>
  
  <pre><code>&lt;GridPane fx:id="grid" fx:controller="application.AddDataController"&gt;
    [here: ColumnConstraints]
    &lt;children&gt;
      &lt;Button fx:id="addData" text="add" onAction="#bAddData"/&gt; 
      &lt;TextField fx:id="data"/&gt;
    &lt;/children&gt;  
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>My Scene 1 controller (controller) looks like this:</p>
  
  <pre><code>public class Controller implements Initializable  {
    @FXML Button goToScene2;
    @FXML VBox parentBox;
  
    @Override
    public void initialize(URL location, ResourceBundle resources) {
    }
  
    public void addData(String s) {
      Label lbl = new Label(s);
      VBox dataBox = new VBox();
      dataBox.setPadding(new Insets(15, 5, 15, 5));
      dataBox.setSpacing(5);
      dataBox.setMaxHeight(80);
      dataBox.getChildren().add(lbl);
      parentBox.getChildren().add(dataBox);
    }
  }
  </code></pre>
  
  <p>This is designed as it is because the dataBox contains more elements than the label, but that doesn't seem relevant to me in this context.</p>
  
  <p>My Scene 2 controller (addDataController) looks like this:</p>
  
  <pre><code>@FXML Button addData;
  @FXML TextField data;
  
  @FXML protected void bAddData(){
    String content = data.getText();    
    FXMLLoader fxmlLoader = new FXMLLoader();
    Pane p = fxmlLoader.load(getClass().getResource("scn1.fxml").openStream());
    Controller cont = (Controller) fxmlLoader.getController();
  
    cont.addData(content);
  }
  </code></pre>
  
  <p>So, when one clicks on the Add-Data-Button in Scene 2, the triggered method passes the entered data to the Controller of Scene 1. This is because the new data should be displayed in Scene 1 now. </p>
  
  <p>I feel like the logic does not work (edited here), because when I ask for</p>
  
  <pre><code>System.out.println(parentBox.getChildren().size();
  </code></pre>
  
  <p>before and after the data was added, it always has one single Child, even though it should have one more...</p>
  
  <p>If I artificially fill a String-Array and move everything from addData to(String s) to Initialize(...), it does work and the data shows up as VBoxes in the parent-VBox.</p>
  
  <p>I didn't post the main class, because loading Controllers and Scene change is not an issue.</p>
  
  <p>Thank you all very very much for your help! :)</p>