title: JavaFX read from text file and display in textarea
body: <p>I am new to JavaFX and JavaFX Scene Builder and have been researching and trying to figure out for weeks now how to simply read from a text file and display its contents in a textarea. I have a good file reading function in my controller class, but I can't figure out how to display the text file to the text area in the fxml document. I've learned how to click a button and make the file display in the text area, but I want to have the contents in the text area as soon as the GUI loads. If anyone has an idea how to go about doing this, your help will be greatly appreciated!</p>
  
  <p>The last button and text area (towards the end of the FXML document) is the button that prints my text file to netbeans, and the text area in which I would like the text to be dispalyed.</p>
  
  <p>Here is my code:</p>
  
  <p>Controller</p>
  
  <pre><code>import java.io.File;
  import java.io.FileNotFoundException;
  import java.net.URL;
  import java.util.ResourceBundle;
  import java.util.Scanner;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  
  
  public class Screen2Controller implements Initializable , ControlledScreen {
  
      ScreensController myController;
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          // TODO
      }
  
      public void setScreenParent(ScreensController screenParent){
          myController = screenParent;
      }
  
      @FXML
      private void goToScreen1(ActionEvent event){
         myController.setScreen(ScreensFramework.screen1ID);
      }
  
      @FXML
      private void goToProgram(ActionEvent event){
         myController.setScreen(ScreensFramework.programID);
      }
  
      private void displayText() throws FileNotFoundException {
          Scanner s = new Scanner (new File ("EECS.txt")).useDelimiter("\\s+");
          while (s.hasNext()) {
              if (s.hasNextInt()) { // check if next token is an int
                  System.out.print(s.nextInt()+" "); // display the found integer
              }       
              else {
                  System.out.print(s.next()+" "); // else read the next token
              }
          } //end while
      } //end main   
  } //end screen2controller
  </code></pre>
  
  <p>FXML</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.image.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import java.util.*?&gt;
  &lt;?import javafx.scene.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.text.*?&gt;
  
  &lt;AnchorPane id="AnchorPane" prefHeight="650.0" prefWidth="1350.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="departmentdisplay.Screen2Controller"&gt;
    &lt;children&gt;
        &lt;ImageView fitHeight="783.0" fitWidth="1398.0" layoutX="-4.0" layoutY="-80.0" pickOnBounds="true" preserveRatio="true"&gt;
           &lt;image&gt;
              &lt;Image url="@nexus_blue.jpg" /&gt;
           &lt;/image&gt;
        &lt;/ImageView&gt;
        &lt;ImageView fitHeight="149.0" fitWidth="1322.0" layoutX="20.0" layoutY="7.0" pickOnBounds="true" preserveRatio="true"&gt;
           &lt;image&gt;
              &lt;Image url="@departinfohead.png" /&gt;
           &lt;/image&gt;
        &lt;/ImageView&gt;
    &lt;Button layoutX="49.0" layoutY="26.0" mnemonicParsing="false" onAction="#goToScreen1" prefHeight="111.0" prefWidth="121.0"&gt;
           &lt;graphic&gt;
              &lt;ImageView fitHeight="100.0" fitWidth="150.0" pickOnBounds="true" preserveRatio="true"&gt;
                 &lt;image&gt;
                    &lt;Image url="@backarrow.png" /&gt;
                 &lt;/image&gt;
              &lt;/ImageView&gt;
           &lt;/graphic&gt;&lt;/Button&gt;
        &lt;SplitPane dividerPositions="0.20765027322404372" layoutX="928.0" layoutY="168.0" orientation="VERTICAL" prefHeight="185.0" prefWidth="415.0"&gt;
           &lt;items&gt;
              &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="95.0" prefWidth="183.0"&gt;
                 &lt;children&gt;
                    &lt;Label layoutX="14.0" layoutY="23.0" prefHeight="96.0" prefWidth="158.0" text="                      Map" textAlignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
                       &lt;font&gt;
                          &lt;Font name="Arial Black" size="24.0" /&gt;
                       &lt;/font&gt;
                    &lt;/Label&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
              &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="176.0" prefWidth="158.0"&gt;
                 &lt;children&gt;
                    &lt;TextArea prefHeight="151.0" prefWidth="242.0" text="Image" wrapText="true" AnchorPane.bottomAnchor="-7.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;       
                    &lt;/TextArea&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
           &lt;/items&gt;
        &lt;/SplitPane&gt;
        &lt;SplitPane dividerPositions="0.08057851239669421" layoutX="20.0" layoutY="168.0" orientation="VERTICAL" prefHeight="480.0" prefWidth="898.0"&gt;
           &lt;items&gt;
              &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"&gt;
                 &lt;children&gt;
                    &lt;Label layoutX="369.0" prefHeight="29.0" prefWidth="1062.0" text="                  Electrical Engineering &amp;amp; Computer Science" textAlignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
                       &lt;font&gt;
                          &lt;Font name="Arial Black" size="24.0" /&gt;
                       &lt;/font&gt;
                    &lt;/Label&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
              &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"&gt;
                 &lt;children&gt;
                    &lt;TextArea fx:id="dinfoTextArea" layoutY="3.0" prefHeight="453.0" prefWidth="896.0" 
                   text="Text file text goes here" wrapText="true"
                    AnchorPane.bottomAnchor="-14.0" AnchorPane.leftAnchor="0.0"
                     AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="3.0"&gt;
                       &lt;/TextArea&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
           &lt;/items&gt;
        &lt;/SplitPane&gt;
        &lt;SplitPane dividerPositions="0.13286713286713286" layoutX="930.0" layoutY="365.0" orientation="VERTICAL" prefHeight="282.0" prefWidth="413.0"&gt;
           &lt;items&gt;
              &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="50.0" prefWidth="221.0"&gt;
                 &lt;children&gt;
                    &lt;Label layoutX="92.0" layoutY="12.0" prefHeight="29.0" prefWidth="263.0" text="                  Programs" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
                       &lt;font&gt;
                          &lt;Font name="Arial Black" size="24.0" /&gt;
                       &lt;/font&gt;
                    &lt;/Label&gt;
                &lt;Button layoutX="25.0" mnemonicParsing="false" onAction="#displayText" prefHeight="34.0" prefWidth="102.0" text="Go To Programs" /&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
              &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="176.0" prefWidth="158.0"&gt;
                 &lt;children&gt;
                    &lt;TextArea layoutX="57.0" layoutY="-6.0" prefHeight="339.0" prefWidth="240.0"
                        text="Lorem ipsum " wrapText="true" AnchorPane.bottomAnchor="0.0"
                        AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" 
                        AnchorPane.topAnchor="0.0"&gt; 
                    &lt;/TextArea&gt;
                 &lt;/children&gt;
              &lt;/AnchorPane&gt;
           &lt;/items&gt;
        &lt;/SplitPane&gt;
    &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>