title: How to listen for WindowEvent.WINDOW_SHOWN in the nodes of the scene graph?
body: <p>It seems WindowEvent.WINDOW_SHOWN never gets dispatched on any of the nodes in the scene graph, nor is there anyway (that I could find) to know when a node is visible/rendered/shown. For example:</p>
  
  <p><em>TestLauncher.java</em></p>
  
  <pre><code>package com.example.javafx.event;
  
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  
  public class TestLauncher extends Application
  {
      public static void main(String[] args)
      {
          Application.launch(TestLauncher.class, args);
      }
  
      @Override
      public void start(Stage stage) throws Exception
      {
          Parent root = FXMLLoader.load(TestController.class.getResource("TestView.fxml"));
          Scene scene = new Scene(root);
          stage.setScene(scene);
          stage.show();
      }
  }
  </code></pre>
  
  <p><em>TestController.java</em></p>
  
  <pre><code>package com.example.javafx.event;
  
  import java.net.URL;
  import java.util.ResourceBundle;
  import javafx.event.EventHandler;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.Parent;
  import javafx.scene.control.TextField;
  import javafx.stage.WindowEvent;
  
  public class TestController implements Initializable
  {
      @FXML private Parent root;
      @FXML private TextField serverAddressInput;
      @FXML private TextField usernameInput;
  
      @Override
      public void initialize(URL url, ResourceBundle rb)
      {
          serverAddressInput.setText("127.0.0.1");
  
          //won't work because stage isn't visible yet
          trySetFocusOnUsernameInput1();
  
          //apparently Stage never passes on any WindowEvents to the children...
          trySetFocusOnUsernameInput2();
      }
  
      private void trySetFocusOnUsernameInput1()
      {
          usernameInput.requestFocus();
      }
  
      private void trySetFocusOnUsernameInput2()
      {
          root.addEventFilter(WindowEvent.WINDOW_SHOWN, new EventHandler&lt;WindowEvent&gt;()
          {
              @Override
              public void handle(WindowEvent window)
              {
                  usernameInput.requestFocus();
              }
          });
  
          root.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler&lt;WindowEvent&gt;()
          {
              @Override
              public void handle(WindowEvent window)
              {
                  usernameInput.requestFocus();
              }
          });
      }
  
      public void handleWindowShownEvent()
      {
          usernameInput.requestFocus();
      }
  }
  </code></pre>
  
  <p><em>TestView.fxml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  
  &lt;VBox
      xmlns:fx="http://javafx.com/fxml"
  
      fx:id="root"
      fx:controller="com.example.javafx.event.TestController"
  
      prefHeight="150"
      prefWidth="200"
  &gt;
      &lt;children&gt;
          &lt;TextField fx:id="serverAddressInput" /&gt;
          &lt;TextField fx:id="usernameInput" /&gt;
      &lt;/children&gt;
  &lt;/VBox&gt;
  </code></pre>
  
  <p>So, actually, how else can a node become aware of the fact that it's visible/rendered/shown?</p>