title: getting text from textfield java fxml
body: <p>Here is my fxml code and Java controller file code. I am trying to get the text from the TEXTFIELD tf in the handle event using "String s = tf.getText().toString();" but it is not getting executed.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.geometry.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  
  &lt;AnchorPane fx:id = "aPane" prefHeight="268.0" prefWidth="379.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="sample.searchController"&gt;
    &lt;children&gt;
    &lt;VBox layoutX="20.0" layoutY="36.0" prefHeight="232.0" prefWidth="333.0"&gt;
       &lt;children&gt;
          &lt;HBox prefHeight="36.0" prefWidth="333.0"&gt;
             &lt;children&gt;
                &lt;Label fx:id= "kw" text="Key Word : "&gt;
                   &lt;padding&gt;
                      &lt;Insets right="10.0" /&gt;
                   &lt;/padding&gt;
                &lt;/Label&gt;
                &lt;TextField fx:id="tf" prefHeight="25.0" prefWidth="120.0" /&gt;
                &lt;Button fx:id="srch" mnemonicParsing="false" onAction="#handle" text="Search" &gt;
                   &lt;HBox.margin&gt;
                      &lt;Insets left="10.0" /&gt;
                   &lt;/HBox.margin&gt;
                &lt;/Button&gt;
             &lt;/children&gt;
             &lt;padding&gt;
                &lt;Insets left="6.0" top="6.0" /&gt;
             &lt;/padding&gt;
             &lt;VBox.margin&gt;
                &lt;Insets /&gt;
             &lt;/VBox.margin&gt;
             &lt;opaqueInsets&gt;
                &lt;Insets /&gt;
             &lt;/opaqueInsets&gt;
          &lt;/HBox&gt;
          &lt;TextArea fx:id="ta" prefHeight="174.0" prefWidth="282.0" /&gt;
       &lt;/children&gt;
    &lt;/VBox&gt;
    &lt;/children&gt;
    &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>JAVA controller Code :</p>
  
  <pre><code>public class searchController implements Initializable,EventHandler&lt;ActionEvent&gt; {
  
    AnchorPane aPane = new AnchorPane();
    Label kw = new Label();
    public TextField tf;
    Button srch = new Button();
    TextArea ta = new TextArea();
    //Text t;
    String s = "priyam";
  
    @Override
    public void initialize(URL location, ResourceBundle resources) {
      // TODO Auto-generated method stub
      tf = new TextField();
    }
  
    @Override
    public void handle(ActionEvent arg0) {
      // TODO Auto-generated method stub
      s=tf.getText().toString();
      System.out.println(s);
    }
  }
  </code></pre>