I have an application in which I call the following code when an exception occurs, i.e. it is inside the catch / try / catch. It simply creates a pop-up window in which the user is prompted to enter int instead.
Stage dialogStage = new Stage();
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.setScene(new Scene(VBoxBuilder.create().
children(new Text("Please enter an integer."), new Button("Ok.")).
alignment(Pos.CENTER).padding(new Insets(5)).build()));
dialogStage.show();
The only problem is that the stage is delayed even if the primary stage (that is, the parameter in the public empty start (Stage primaryStage)) is closed.
What have I tried ?:
I made the dialog box visible throughout the class, specifying it as a class variable. Then I executed the following code:
primaryStage.setOnCloseRequest((new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent arg0) {
arg0.consume();
try
{
dialogStage.close();
}
catch(Exception ex)
{
System.out.print(ex.getMessage()+"\r\n");
}
}
}));
}
"" , , , , : , .
, , , try/catch .
, , , dialogstage , , try/catch.