2017-06-04 3 views
0

Je peux ajouter ce code à accrocher dans la scène événement close:Comment arrêter la fermeture d'une scène lorsque l'utilisateur sélectionne le bouton de fermeture?

stage.setOnCloseRequest(new EventHandler<WindowEvent>() { 
    public void handle(WindowEvent we) { 
     System.out.println("Stage is closing"); 
     // but wait! I don't want it to close! 
    } 
}); 

mais comment puis-je arrêter la scène de fermeture?

+0

Pour [exemple] (https://stackoverflow.com/q/17003906/230513). – trashgod

Répondre

1

Je me réfère à this commentaire:

Platform.setImplicitExit(false); 

primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { 
    @Override 
    public void handle(WindowEvent event) { 
     event.consume(); 
    } 
});