title: JavaFX Label not updating with setText()
body: <p>I have done a lot of searching and cannot seem to find a solution to my problem, I am trying to get the label <em>selectedName</em> to update when the user enters his/her name inside Intro.fxml and appear on Main.fxml. However it still appears as default_user which is set in the initialize method. Admittedly the code is a bit of a mess, but it's just a little project I'm working on.</p>
  
  <p><strong>LogicController.java</strong> not the whole file</p>
  
  <pre><code>public class LogicController{ 
  
  /** CLASS OBJECTS
   * 
   */
  
  private LoadWords loadWords = new LoadWords();
  private GameLogic game = new GameLogic();
  
  /** AUDIO FILES 
   * items used for audio
   * All wavs are free
   * provided on freesound.org
   * **/
  
  final URL resource = getClass().getResource("sounds/beep.wav");
  final AudioClip menuClick = new AudioClip(resource.toString());
  
  /** OTHER DECLARATIONS
   * other variables
   * 
   * 
   */
  
  @FXML public ChoiceBox&lt;String&gt; difficultyBox = new ChoiceBox&lt;String&gt;();
  @FXML public ObservableList&lt;String&gt; difficultyBoxList = FXCollections.observableArrayList("Easiest", "Easy", "Medium", "Hard");
  @FXML public String selectedDifficulty; 
  @FXML public TextField myName;
  @FXML public Label selectedName = new Label(); 
  
  @FXML  
  public void initialize()
  {
    difficultyBox.setItems(difficultyBoxList);
    selectedName.setText("default_player");
  
  
  }
  
  
  @FXML
  public void loadSerial(MouseEvent mouseEvent) { 
  
      menuClick.play();
      loadWords.startSequential();    
  
      game.setAllLists(loadWords.getAllLists());
      game.setDifficulty(difficultyBox.getSelectionModel().getSelectedItem().toString());
      game.setName(myName.getText());
      selectedName.setText(game.getName().toString());
  
      try{
  
          Node  source = (Node)  mouseEvent.getSource(); 
          Stage intro  = (Stage) source.getScene().getWindow();
          intro.close();          
  
          Parent root = FXMLLoader.load(getClass().getResource("Main.fxml")); 
          root.setId("pane");
  
          Scene scene = new Scene(root, 900, 506);
          Stage primaryStage = new Stage();
  
          primaryStage.setTitle("x");
          scene.getStylesheets().addAll(this.getClass().getResource("application.css").toExternalForm());
          primaryStage.setResizable(false);
          primaryStage.setScene(scene);
          primaryStage.show();
  
        }catch(Exception e) {
            e.printStackTrace();
        }
  
  
  }
  </code></pre>
  
  <p><strong>Intro.fxml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.ChoiceBox?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.control.TextField?&gt;
  &lt;?import javafx.scene.effect.DropShadow?&gt;
  &lt;?import javafx.scene.effect.Glow?&gt;
  &lt;?import javafx.scene.image.Image?&gt;
  &lt;?import javafx.scene.image.ImageView?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.layout.ColumnConstraints?&gt;
  &lt;?import javafx.scene.layout.FlowPane?&gt;
  &lt;?import javafx.scene.layout.GridPane?&gt;
  &lt;?import javafx.scene.layout.Pane?&gt;
  &lt;?import javafx.scene.layout.RowConstraints?&gt;
  &lt;?import javafx.scene.layout.StackPane?&gt;
  &lt;?import javafx.scene.text.Font?&gt;
  
  &lt;AnchorPane id="fx" prefHeight="538.0" prefWidth="923.0" style="-fx-background-color: #4f0f41;" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.LogicController"&gt;
     &lt;children&gt;
        &lt;StackPane prefHeight="538.0" prefWidth="923.0"&gt;
           &lt;children&gt;
              &lt;Pane prefHeight="545.0" prefWidth="929.0"&gt;
                 &lt;children&gt;
                    &lt;Label layoutX="265.0" layoutY="101.0" prefHeight="103.0" prefWidth="394.0" style="-fx-font-family: Paperland; -fx-font-size: 90;" stylesheets="@application.css" text="FANGMAN" textFill="WHITE"&gt;
                       &lt;effect&gt;
                          &lt;Glow /&gt;
                       &lt;/effect&gt;
                       &lt;font&gt;
                          &lt;Font size="66.0" /&gt;
                       &lt;/font&gt;
                    &lt;/Label&gt;
                    &lt;Label layoutX="265.0" layoutY="69.0" prefHeight="65.0" prefWidth="79.0" style="-fx-font-family: Paperland; -fx-font-size: 40;" stylesheets="@application.css" text="THE" textFill="WHITE"&gt;
                       &lt;effect&gt;
                          &lt;Glow /&gt;
                       &lt;/effect&gt;
                    &lt;/Label&gt;
                    &lt;Label layoutX="694.0" layoutY="24.0" text="An adaptation by Benjamin Meysner" textFill="WHITE" /&gt;
                    &lt;FlowPane layoutX="266.0" layoutY="288.0" prefHeight="225.0" prefWidth="378.0"&gt;
                       &lt;children&gt;
                          &lt;GridPane prefHeight="230.0" prefWidth="398.0"&gt;
                            &lt;columnConstraints&gt;
                              &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="171.0" minWidth="10.0" prefWidth="171.0" /&gt;
                              &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="265.0" minWidth="10.0" prefWidth="64.0" /&gt;
                                &lt;ColumnConstraints hgrow="SOMETIMES" maxWidth="233.0" minWidth="0.0" prefWidth="152.0" /&gt;
                            &lt;/columnConstraints&gt;
                            &lt;rowConstraints&gt;
                              &lt;RowConstraints /&gt;
                              &lt;RowConstraints maxHeight="51.0" minHeight="5.0" prefHeight="48.0" /&gt;
                              &lt;RowConstraints maxHeight="172.0" minHeight="10.0" prefHeight="109.0" vgrow="SOMETIMES" /&gt;
                                &lt;RowConstraints maxHeight="78.0" minHeight="10.0" prefHeight="41.0" vgrow="SOMETIMES" /&gt;
                                &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
                            &lt;/rowConstraints&gt;
                             &lt;children&gt;
                                &lt;ImageView id="zomb" fx:id="zomb" fitHeight="150.0" fitWidth="200.0" onMouseClicked="#loadSerial" onMouseEntered="#zombieHover" pickOnBounds="true" preserveRatio="true" style="-fx-cursor: hand;" styleClass="zomb" GridPane.rowIndex="2"&gt;
                                   &lt;image&gt;
                                      &lt;Image url="@images/chtr1.png" /&gt;
                                   &lt;/image&gt;
                                   &lt;effect&gt;
                                      &lt;Glow /&gt;
                                   &lt;/effect&gt;
                                &lt;/ImageView&gt;
                                &lt;ImageView id="skul" fitHeight="150.0" fitWidth="200.0" onMouseClicked="#loadParallel" onMouseEntered="#skulHover" pickOnBounds="true" preserveRatio="true" style="-fx-cursor: hand;" styleClass="skul" GridPane.columnIndex="2" GridPane.rowIndex="2"&gt;
                                   &lt;image&gt;
                                      &lt;Image url="@images/chtr3.png" /&gt;
                                   &lt;/image&gt;
                                   &lt;effect&gt;
                                      &lt;Glow /&gt;
                                   &lt;/effect&gt;
                                &lt;/ImageView&gt;
                                &lt;Label alignment="CENTER" style="-fx-font-family: Paperland;" text="OR" textFill="WHITE" GridPane.columnIndex="1" GridPane.rowIndex="2"&gt;
                                   &lt;font&gt;
                                      &lt;Font size="50.0" /&gt;
                                   &lt;/font&gt;
                                   &lt;effect&gt;
                                      &lt;Glow /&gt;
                                   &lt;/effect&gt;
                                &lt;/Label&gt;
                                &lt;Label text="Serial" textFill="WHITE" GridPane.rowIndex="3" /&gt;
                                &lt;Label text="Parallel" textFill="WHITE" GridPane.columnIndex="2" GridPane.rowIndex="3" /&gt;
                             &lt;/children&gt;
                          &lt;/GridPane&gt;
                       &lt;/children&gt;
                    &lt;/FlowPane&gt;
                    &lt;ImageView fitHeight="104.0" fitWidth="113.0" layoutX="156.0" layoutY="90.0" pickOnBounds="true" preserveRatio="true"&gt;
                       &lt;image&gt;
                          &lt;Image url="@images/drac.png" /&gt;
                       &lt;/image&gt;
                    &lt;/ImageView&gt;
                    &lt;Label layoutX="252.0" layoutY="262.0" prefHeight="52.0" prefWidth="137.0" text="Now enter your name..." textFill="WHITE" /&gt;
                    &lt;Label layoutX="252.0" layoutY="203.0" prefHeight="78.0" prefWidth="137.0" text="To begin a new game, select a difficulty setting..." textFill="WHITE" wrapText="true" /&gt;
                    &lt;TextField fx:id="myName" layoutX="405.0" layoutY="276.0" promptText="Enter name..."&gt;
                       &lt;effect&gt;
                          &lt;DropShadow height="71.4" radius="30.7525" spread="0.13" width="53.61" /&gt;
                       &lt;/effect&gt;&lt;/TextField&gt;
                    &lt;Label layoutX="115.0" layoutY="281.0" prefHeight="78.0" prefWidth="137.0" text="Finally select a load option (Serial or Parallel)" textFill="WHITE" wrapText="true" /&gt;
                    &lt;ChoiceBox fx:id="difficultyBox" layoutX="404.0" layoutY="225.0" prefWidth="150.0" value="Easiest"&gt;
                       &lt;effect&gt;
                          &lt;DropShadow height="0.0" radius="29.2125" spread="0.19" width="118.85" /&gt;
                       &lt;/effect&gt;
                    &lt;/ChoiceBox&gt;
                 &lt;/children&gt;
              &lt;/Pane&gt;
           &lt;/children&gt;
        &lt;/StackPane&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p><strong>Main.fxml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.effect.Glow?&gt;
  &lt;?import javafx.scene.image.Image?&gt;
  &lt;?import javafx.scene.image.ImageView?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.layout.ColumnConstraints?&gt;
  &lt;?import javafx.scene.layout.GridPane?&gt;
  &lt;?import javafx.scene.layout.Pane?&gt;
  &lt;?import javafx.scene.layout.RowConstraints?&gt;
  &lt;?import javafx.scene.text.Font?&gt;
  
  &lt;AnchorPane style="-fx-background-color: #4f0f41;" stylesheets="@application.css" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.LogicController"&gt;
     &lt;children&gt;
        &lt;Pane prefHeight="506.0" prefWidth="900.0" stylesheets="@application.css"&gt;
           &lt;children&gt;
              &lt;ImageView fitHeight="197.0" fitWidth="183.0" layoutX="35.0" pickOnBounds="true" preserveRatio="true"&gt;
                 &lt;image&gt;
                    &lt;Image url="@images/drac.png" /&gt;
                 &lt;/image&gt;
              &lt;/ImageView&gt;
              &lt;Label layoutX="37.0" layoutY="223.0" text="Welcome" textFill="WHITE" /&gt;
              &lt;Label fx:id="selectedName" layoutX="97.0" layoutY="218.0" prefHeight="27.0" prefWidth="121.0" text="  " textFill="WHITE"&gt;
                 &lt;font&gt;
                    &lt;Font size="13.0" /&gt;
                 &lt;/font&gt;
                 &lt;effect&gt;
                    &lt;Glow /&gt;
                 &lt;/effect&gt;
              &lt;/Label&gt;
              &lt;Pane layoutX="24.0" layoutY="211.0" opacity="0.45" prefHeight="127.0" prefWidth="200.0" style="-fx-background-color: BLACK;"&gt;
                 &lt;children&gt;
                    &lt;GridPane layoutX="13.0" layoutY="34.0" prefHeight="81.0" prefWidth="153.0"&gt;
                      &lt;columnConstraints&gt;
                        &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /&gt;
                        &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /&gt;
                      &lt;/columnConstraints&gt;
                      &lt;rowConstraints&gt;
                        &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
                        &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
                          &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
                      &lt;/rowConstraints&gt;
                       &lt;children&gt;
                          &lt;Label text="Games Won" textFill="WHITE" /&gt;
                          &lt;Label text="Games Lost" textFill="WHITE" GridPane.rowIndex="1" /&gt;
                          &lt;Label text="Win Ratio" textFill="WHITE" GridPane.rowIndex="2" /&gt;
                          &lt;Label text="0" textFill="WHITE" GridPane.columnIndex="1" /&gt;
                          &lt;Label text="0" textFill="WHITE" GridPane.columnIndex="1" GridPane.rowIndex="1" /&gt;
                          &lt;Label text="0%" textFill="WHITE" GridPane.columnIndex="1" GridPane.rowIndex="2" /&gt;
                       &lt;/children&gt;
                    &lt;/GridPane&gt;
                 &lt;/children&gt;
              &lt;/Pane&gt;
              &lt;Pane layoutX="246.0" layoutY="61.0" opacity="0.45" prefHeight="421.0" prefWidth="633.0" style="-fx-background-color: BLACK;" /&gt;
              &lt;Button layoutX="355.0" layoutY="22.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="100.0" text="save game" /&gt;
              &lt;Pane layoutX="25.0" layoutY="373.0" opacity="0.45" prefHeight="104.0" prefWidth="200.0" style="-fx-background-color: BLACK;" /&gt;
              &lt;Button layoutX="244.0" layoutY="22.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="100.0" text="load game" /&gt;
              &lt;Button layoutX="469.0" layoutY="22.0" mnemonicParsing="false" onAction="#newWord" prefHeight="26.0" prefWidth="100.0" text="new word" /&gt;
              &lt;Label layoutX="28.0" layoutY="484.0" text="message box" textFill="WHITE" /&gt;
              &lt;Label layoutX="28.0" layoutY="346.0" text="statistics" textFill="WHITE" /&gt;
              &lt;Label layoutX="246.0" layoutY="484.0" text="game view" textFill="WHITE" /&gt;
           &lt;/children&gt;
        &lt;/Pane&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p><strong>IMAGES HERE</strong>
  <a href="https://i.stack.imgur.com/LOWWc.jpg" rel="nofollow noreferrer">intro.fxml</a>
  <a href="https://i.stack.imgur.com/cb1Q7.jpg" rel="nofollow noreferrer">main.fxml</a>
  Any help would be appreciated!</p>