title: JavaFX - Update a text field through observer pattern
body: <p>I am trying to update a text field through observer pattern. The update function in the observer (FXML controller) is called after clicking on a listItem in another controller class. And that works fine. The only problem is that my textfield won't update.</p>
  
  <p>Here is my update function in the observer.</p>
  
  <pre><code>@Override
  public void update(Observable o, final Object arg) {
      System.out.println("test");         // works
      firstNameTextField.setText("test"); // doesn't work (text field is still empty)
      System.out.println(firstNameTextField.getText()); //works and shows me the word "test" on my console
  }
  </code></pre>
  
  <p>The funny thing is, if I print the text from the text field on my console it's printing the word "test" on the console. It seems like the text field value is updated but it doesn't show up on the ui.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  This is my MainController</p>
  
  <pre><code>public class MainController extends Observable implements Initializable {
  
      private ObservableList&lt;String&gt; items = FXCollections.observableArrayList("item1", "item2");
      private List&lt;UserProfile&gt; userProfiles = new ArrayList&lt;UserProfile&gt;();
      private String[] tabTitles = { "Profile"};
  
      @FXML
      private TabPane tabPane;
  
      @FXML
      ListView&lt;String&gt; listView;
  
      @Override
      public void initialize(URL arg0, ResourceBundle arg1) {
  
          for (String tabTitle : tabTitles) {
          Tab tab = new Tab(tabTitle);
          tab.setClosable(false);
          tabPane.getTabs().add(tab);
      }
  
      tabPane.getSelectionModel().clearSelection();
  
      for (Tab tab : tabPane.getTabs()) {
          try {
              String newStringValue = tab.getText();
  
              Parent root = FXMLLoader.load(getClass().getResource("profile.fxml"));
              tab.setContent(root);
  
  
          FXMLLoader fxmlLoader = new FXMLLoader();
  
          Object p = fxmlLoader.load(getClass().getResource("profile.fxml").openStream());
          if (fxmlLoader.getController() instanceof ProfileController) {
              ProfileController profileController = (ProfileController) fxmlLoader.getController();
              this.addObserver(profileController);
          }
      } catch (IOException e) {
          e.printStackTrace();
      }
      }
       tabPane.getSelectionModel().selectFirst();
  
      listView.setItems(items);
      listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener&lt;String&gt;() {
  
          @Override
          public void changed(ObservableValue&lt;? extends String&gt; observable, String oldValue, String newValue) {
              setChanged();
              notifyObservers();
          }
  
      });
  
  }
  }
  </code></pre>
  
  <p>ProfileController</p>
  
  <pre><code>public class ProfileController implements Initializable, Observer {
  
      @FXML
      TextField firstNameTextField;
  
      @Override
      public void initialize(URL arg0, ResourceBundle arg1) {
      }
  
      @Override
      public void update(Observable o, final Object arg) {
          System.out.println("test");         // works
          firstNameTextField.setText("test"); // doesn't work (text field is still empty)
          System.out.println(firstNameTextField.getText()); //works and shows me the word "test" on my console
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Can anybody help me out with this?</p>
  
  <p>Thanks!</p>