I'm looking for an "windows close" Swing event.
I'm looking for an "windows close" Swing event.
You can call the setOnCloseRequest method of your < the Stage, so you can perform an action as soon as the user clicks on the button to close the window.
Ex:
public class Teste extends Application {
@Override
public void start(Stage stage) {
stage.setOnCloseRequest(event -> System.out.println("Fechando o programa"));
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
}
public static void main(String[] args) {
launch(args);
}
}