title: Filter Keyboard TextField Java FXML
body: <p>Well I'm studying Java FX, but this time I'm using FXML in NetBeans, then I want to restric the Keys allowed by a TextField. Like just numbers or just Letters.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/19167750/control-keyboard-input-into-javafx-textfield">This</a> , then I created a new class, then put that code (the checked as correct in the link), i extend TextField, but when I run the code, throws a exception, I think is because SceneBuilder doesn't have my Class. </p>
  
  <p>Update i found a similar code for Java FX :</p>
  
  <pre><code>import java.util.function.UnaryOperator;
  import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.TextField;
  import javafx.scene.control.TextFormatter;
  import javafx.scene.control.TextFormatter.Change;
  import javafx.scene.layout.VBox;
  import javafx.stage.Stage;
  
  /**
   *
   * @author Alejandro
   */
  public class JavaFXApplication2 extends Application {
  
  @Override
  public void start(Stage primaryStage) {
  
      TextField textField = new TextField();
      TextFormatter&lt;String&gt; textFormatter = getTextFormatter();
      textField.setTextFormatter(textFormatter);
  
      VBox root = new VBox();
  
      root.getChildren().add(textField);
  
      Scene scene = new Scene(root, 300, 250);
  
      primaryStage.setTitle("TextFormat");
      primaryStage.setScene(scene);
      primaryStage.show();
  }
  
   private TextFormatter&lt;String&gt; getTextFormatter() {
      UnaryOperator&lt;Change&gt; filter = getFilter();
      TextFormatter&lt;String&gt; textFormatter = new TextFormatter&lt;&gt;(filter);
      return textFormatter;
  }
  
  private UnaryOperator&lt;Change&gt; getFilter() {
      return change -&gt; {
          String text = change.getText();
  
          if (!change.isContentChange()) {
              return change;
          }
  
          if (text.matches("[a-z]*") || text.isEmpty()) {
              return change;
          }
  
          return null;
       };
  }
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      launch(args);
  }
  
  }
  </code></pre>
  
  <p>That code above works fine in a Java FX app, but I need one to use in Java FXML, one guy below Post a similar code, it compiles, no trows exception, but doesn't work, or i don't know how to implement it.</p>