简体   繁体   中英

How to dismiss an alert in JavaFX?

I need to have a sort of "blocked alert" that can't be dismissed by the user until some event occurs. So, I created the alert and removed all the buttons from it:

Alert waitingAlert = new Alert(Alert.AlertType.INFORMATION);
waitingAlert.setTitle("Proposta Inviata");
waitingAlert.getButtonTypes().setAll();

waitingAlert.setHeaderText("La proposta è stata inviata a " + trade.getPlayer2Name());
waitingAlert.showAndWait(); 

Then, I need to dismiss it when a particular event occurs. I just tried doing it this way:

waitingAlert.close();

But it doesn't work.

Edit
The panel is shown when an user wants to send a request to another user in the network that needs to be accepted or refused. The principle is that the UI gets blocked until the other user says if he has accepted or refused the request. The request is send through a remote method invokation through a ring network. When I receive the response I want to close dismiss the panel.

To have a dialog that can't be dismissed by the user, but wait on a process, you will need to use dialog.show() as noted by James_D.

However, without buttons, the dialog actually will not close and you need to force it.

//for example
dialog.getButtonTypes().add(ButtonType.CANCEL);
dialog.hide();
dialog.getButtonTypes().remove(ButtonType.CANCEL);

This will allow you to close a dialog which has no buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM