belyid belyid - 1 month ago 11
Java Question

Why am I unable to programmatically close a Dialog on JavaFX?

This sample of code shows but doesn't close a javafx.scene.control.Dialog on JavaFx:

Dialog<Void> dialog = new Dialog<Void>();
dialog.show();
dialog.close();


or

Dialog<Void> dialog = new Dialog<Void>();
dialog.show();
dialog.hide();


Why?

Answer

From the javadoc:

More often than not, dialogs are shown in a modal and blocking fashion. 'Modal' means that the dialog prevents user interaction with the owning application whilst it is showing, and 'blocking' means that code execution stops at the point in which the dialog is shown

(emphasis mine)