It seems that WindowEvent.WINDOW_SHOWN never goes to any of the nodes in the scene graph and does not exist (what I can find) to know when the node is displayed / displayed / displayed. For example:
TestLauncher.java
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(); } }
TestController.java
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");
TestView.fxml
<?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <VBox xmlns:fx="http://javafx.com/fxml" fx:id="root" fx:controller="com.example.javafx.event.TestController" prefHeight="150" prefWidth="200" > <children> <TextField fx:id="serverAddressInput" /> <TextField fx:id="usernameInput" /> </children> </VBox>
So actually, how else can a node know that it is being displayed / displayed / displayed?
Andrey
source share