I want to automatically show an alert box again after closing it, this is based on a certain condition. Here's my code:
protected void showInputDialog()
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("AddRecordDialog.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root);
AddRecordDialogController addRecordDialogController = (AddRecordDialogController)loader.getController();
addRecordDialogController.setAddNewSalesDialogController(this);
addRecordDialogController.setInvoice(this.invoice);
this.addRecordDialog = new Stage();
this.addRecordDialog.setTitle("Add Record");
this.addRecordDialog.initModality(Modality.APPLICATION_MODAL);
this.addRecordDialog.initOwner(root.getScene().getWindow());
this.addRecordDialog.setScene(scene);
this.addRecordDialog.sizeToScene();
this.addRecordDialog.setResizable(false);
//Event handler for when a Window is closed.
this.addRecordDialog.setOnHiding(new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent we)
{
if(nextItem == true)
showInputDialog();
nextItem = false;
}
});
this.addRecordDialog.showAndWait();
}
The second dialog shows up but the first dialog doesn't disappear.
The dialog is programmatically closed with a stage.close();
somewhere else.
I saw here that you need to call the setOnHiding
method for a programmatically closing event.
If I remove the event handler the previous stage will close.
But I want to open a new instance of that stage again after it is closed.
Please help.
Edit: ...yes I checked for the nextItem
variable it was true
,
I used System.out.println("Next Item: " + nextItem);