If I just create an empty class extending from javafx.scene.control.Dialog, it won\'t close when I\'m pressing the \"x\" button in the top right corner
To quote the Api Docs:
JavaFX dialogs can only be closed 'abnormally' (as defined above) in two situations:
When the dialog only has one button, or
When the dialog has multiple buttons, as long as one of them meets one of the following requirements:
- The button has a ButtonType whose ButtonData is of type ButtonData.CANCEL_CLOSE.
- The button has a ButtonType whose ButtonData returns true when ButtonData.isCancelButton() is called.
...
So either add at least one button or multiple buttons, and one of them is of type ButtonData.CANCEL_CLOSE, for example:
Dialog dialog = new Dialog<>();
dialog.getDialogPane().getButtonTypes().add(new ButtonType("Got it!", ButtonData.CANCEL_CLOSE));
dialog.setContentText("test");
dialog.showAndWait();
Edit:
This behavior is implemented in javafx.scene.control.FXDialog.requestPermissionToClose(Dialog>), but the real FXDialog shown is HeavyweightDialog which is not public API so not really an extension point.