/** Method to close the pop up and remove the background mask. */ public void hide() { Parent parentRoot = ((Stage) stage.getOwner()).getScene().getRoot(); if (parentRoot instanceof StackPane) { ((StackPane) parentRoot).getChildren().remove(mask); } stage.close(); }