title: JavaFX label won't update
body: <p>I am trying to learn Java and JavaFX, I followed <a href="http://code.makery.ch/library/javafx-8-tutorial/" rel="nofollow noreferrer">this tutorial</a> and everything worked out fine.</p>
  
  <p>Now I wante to make things a little more complicated and started a password book app.</p>
  
  <p>The main fxml file contains a split pane and one of the two halves is a ListView, the other half is loaded dynamically, so I can change the labels to textFields to edit records in the window. </p>
  
  <p>The problem is that when I click a listView item it loads the .fxml fine but doesn't update the labels. If I add a listener and log the updates it records as if it was changed, but it's not. This is the method to change the label. </p>
  
  <pre><code>public void showLoginDetails(String username)
  {
      usernameLabel.setText(username);
  }
  </code></pre>
  
  <p>Which is called by this method in the parent controller</p>
  
  <pre><code>private void showLoginDetails(Login login)
  {
      mainApp.showLayout("LoginOverview.fxml");
  
      mainApp.getLoginOverviewController().showLoginDetails(login.getName());;
  }
  </code></pre>
  
  <p>I get no errors but the result is this:
  <img src="https://i.stack.imgur.com/sZ3yJ.png" alt="Not working Labels">
  I am sure that the name of the label is set correctly in SceneBuilder.</p>
  
  <p>What code do you need to see be able to help me?</p>
  
  <p>Edit:</p>
  
  <p>MainApp getLoginOverViewController()</p>
  
  <pre><code>public LoginOverviewController getLoginOverviewController()
  {
      if(loginOverviewController == null)
      {
          this.loginOverviewController = (LoginOverviewController) this.getController("LoginOverview.fxml");
          this.loginOverviewController.setMainApp(this);
      }
      return this.loginOverviewController;
  }
  </code></pre>
  
  <p>MainApp.getController()</p>
  
  <pre><code>private Object getController(String layout)
  {
      try {
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(MainApp.class.getResource("view/" + layout));
          loader.load();
          return loader.getController();
  
      } catch (IOException e)
      {
  
          e.printStackTrace();
          return null;
      }
  }
  </code></pre>
  
  <p>The fxmlLoader</p>
  
  <pre><code>public void showLayout(String layout)
  {
      try {
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(MainApp.class.getResource("view/" + layout));
          AnchorPane content = (AnchorPane) loader.load();
          listContainerController.setContent(content);
      } catch (IOException e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>listContainerController.setContent()</p>
  
  <pre><code>public void setContent(AnchorPane layout)
  {
      content.getChildren().clear();
      content.getChildren().add(layout);
  }
  </code></pre>
  
  <p>Here is where the labels are declared</p>
  
  <pre><code>@FXML
  private Label usernameLabel;
  </code></pre>
  
  <p>The label variable is not accessed in the initialize method.</p>
  
  <p>Edit2</p>
  
  <p>As pointed out by James_D I have to store the controller from the ShowLayout method.</p>
  
  <pre><code>public void showLayout(String layout)
  {
      try {
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(MainApp.class.getResource("view/" + layout));
          AnchorPane content = (AnchorPane) loader.load();
          listContainerController.setContent(content);
          this.activeController = loader.getController();
      } catch (IOException e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>The variable.</p>
  
  <pre><code>private Object activeController;
  </code></pre>
  
  <p>the getter.</p>
  
  <pre><code>public Object getActiveController()
  {
      return activeController;
  }
  </code></pre>
  
  <p>Is the code as it stands fine? It works but I'd like to learn how to write acceptable code.</p>
  
  <p>This is how I updated the code</p>