title: JavaFX FXML controller key handler code does not work
body: <p>I have problem with FXML and keyPress handler.</p>
  
  <p>I try to set on key press simple test, but the key handler is not called. Mouse handling, etc works correctly, but keys handling does not. </p>
  
  <p>I tried to setKeyHandler on Pane, circle (in Pane) and scene.</p>
  
  <pre><code>public class Controller implements Initializable {
      public Pane canvas;
      public Label yDisplay;
      public Label xDisplay;
      public Circle circle;
  
      @Override
      public void initialize(URL url, ResourceBundle resourceBundle) {
          canvas.setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
              @Override
              public void handle(KeyEvent keyEvent) {
                  System.out.println("Test");
              }
          });
      }
  }
  </code></pre>
  
  <p>Respected Dil, thx for your answer, but i want did some "game", where simple circle on pane, moved by press on keybord. Of course, with focus on compmonent will work. But whithout focus. Maybe key listener must be set on window or scene? I apologize for the vagueness of purpose.</p>
  
  <p>I tried to set on press, but scence, in Initialization, is null.</p>
  
  <pre><code>public class Controller implements Initializable {
      @FXML private Pane canvas;
      @FXML private Label yDisplay;
      @FXML private Label xDisplay;
      @FXML private Circle circle;
  
      @Override
      public void initialize(URL url, ResourceBundle resourceBundle) {
          canvas.getScene().setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
              @Override
              public void handle(KeyEvent keyEvent) {
                  System.out.println("Work");
              }
          });
          canvas.setOnMousePressed(new EventHandler&lt;MouseEvent&gt;() {
              @Override
              public void handle(MouseEvent mouseEvent) {
                  canvas.getChildren().add(new Bullet(150.0, 150.0, mouseEvent.getX(), mouseEvent.getY()));
              }
          });
      }
  }
  </code></pre>
  
  <p>It's logic, and i tried to set in Apllication class. Set key handler on Application, and it's work! But, how to get Circle and other component of scene, becouse they kepp in controlle.class</p>
  
  <pre><code>  @Override
      public void start(Stage primaryStage) throws Exception {
          Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
          primaryStage.setTitle("Hello World");
          primaryStage.setScene(new Scene(root));
          primaryStage.getScene().setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
              @Override
              public void handle(KeyEvent keyEvent) {
                  System.out.println("HEY");
              }
          });
          primaryStage.show();
      }
  </code></pre>
  
  <p>Right now i tied do it with lookup of scence / Parent root</p>
  
  <p>Yes! lookup of Parent is work. I just must to search by # + "id"</p>
  
  <pre><code> @Override
      public void start(Stage primaryStage) throws Exception {
          Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
          primaryStage.setTitle("Hello World");
          primaryStage.setScene(new Scene(root));
          primaryStage.getScene().setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
              @Override
              public void handle(KeyEvent keyEvent) {
                  System.out.println("HEY");
                  Circle myCirecle = (Circle) root.lookup("#circle");
                  myCirecle.setTranslateY(10.0);
              }
          });
          primaryStage.show();
      }
  </code></pre>