I need a way to close a Stage from within itself by clicking a Button.
I have a main class from which I create the main stage with a scene.
You can derive the stage to be closed from the event passed to the event handler.
new EventHandler() {
@Override public void handle(ActionEvent actionEvent) {
// take some action
...
// close the dialog.
Node source = (Node) actionEvent.getSource();
Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
}