title: JavaFX create and use custom control with it's own functions
body: <p>I have created a simple custom control as shown in picture:<br><img src="https://i.stack.imgur.com/5kdii.png" alt="enter image description here"></p>
  
  <p>when I click on "Click me" button the console shows me this message "The button was clicked!" by a function called <code>doSomething</code>, and this is the custom control's fxml file code:<br></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&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;fx:root prefHeight="83.0" prefWidth="196.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"&gt;
     &lt;children&gt;
        &lt;TextField fx:id="textField" layoutY="2.0" prefHeight="25.0" prefWidth="196.0" /&gt;
        &lt;Button layoutX="72.0" layoutY="29.0" mnemonicParsing="false" onAction="#doSomething" text="Click me" /&gt;
     &lt;/children&gt;
  &lt;/fx:root&gt;
  </code></pre>
  
  <p>And this is the controller of this custom control:<br></p>
  
  <pre><code>package control;
  
  import java.io.IOException;
  
  import javafx.beans.property.StringProperty;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.control.TextField;
  import javafx.scene.layout.AnchorPane;
  
  public class Controller extends AnchorPane {
      @FXML private TextField textField;
  
      public Controller() {
          FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CustomControlView.fxml"));
          fxmlLoader.setRoot(this);
          fxmlLoader.setController(this);
  
          try {
              fxmlLoader.load();
          } catch (IOException exception) {
              throw new RuntimeException(exception);
          }
      }
  
      public String getText() {
          return textProperty().get();
      }
  
      public void setText(String value) {
          textProperty().set(value);
      }
  
      public StringProperty textProperty() {
          return textField.textProperty();
      }
  
      @FXML
      protected void doSomething() {
          System.out.println("The button was clicked!");
      }
  }
  </code></pre>
  
  <p>The control is working good and I can call it in another fxml file using "JavaFX scence builder" (as shown in picture) :<br>
  <img src="https://i.stack.imgur.com/mVpve.png" alt="enter image description here"></p>
  
  <p>And this is the fxml file code:<br></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.text.*?&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 prefHeight="237.0" prefWidth="324.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"&gt;
     &lt;children&gt;
        &lt;javafx.scene.layout.AnchorPane layoutX="64.0" layoutY="92.0" prefHeight="40.0" prefWidth="196.0"&gt;
           &lt;children&gt;
              &lt;TextField fx:id="textField" layoutY="2.0" prefHeight="25.0" prefWidth="196.0" /&gt;
              &lt;Button layoutX="72.0" layoutY="29.0" mnemonicParsing="false" onAction="#doSomething" text="Click me" /&gt;
           &lt;/children&gt;
        &lt;/javafx.scene.layout.AnchorPane&gt;
        &lt;Label layoutX="75.0" layoutY="14.0" text="Trying the custom control:"&gt;
           &lt;font&gt;
              &lt;Font size="15.0" /&gt;
           &lt;/font&gt;
        &lt;/Label&gt;
     &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>But the problem is that I have to redefine the <code>doSomething</code> function of the custom control button !!!I mean when I added my custom conrol to another fxml file all the functions of this custom control should work without redefining it just like <code>Swing</code>.<br>
  Am I wrong ?</p>