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

I'm not sure why the response above has been marked as an answer as it clearly doesn't answer the question. The underlying issue appears to be that it is not possible to programmatically close a dialog box that doesn't have a Close/Cancel button:

Dialog box opens, but doesn't close:

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

To close, add a cancel button to it just before you close it:

Dialog<Void> dialog = new Dialog<Void>();
dialog.show();
// Add dummy cancel button
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL);
// Dialog will now close
dialog.close(); 

A shorter (but not less "hacky" method) is to use a dialog of a specific type (other than Void) and set a (arbitrary) result directly before hiding it, e.g.:

Dialog<Boolean> dialog = new Dialog<Boolean>();
dialog.show();
...
// for closing
dialog.setResult(Boolean.TRUE);
dialog.close();

Tags:

Java

Javafx