* the children of the alert
* @return the alert
*/
public static Stage alert(final Stage parent, final double width, final double height,
final Modality modality, final Node... children) {
final Stage stage = new Stage();
stage.initModality(modality);
stage.initStyle(StageStyle.TRANSPARENT);
final StackPane root = new StackPane();
root.setPrefSize(width, height);
if (children != null) {
root.getChildren().addAll(children);
}
if (parent != null) {
stage.setScene(new Scene(root, parent.getWidth(), parent.getHeight(), Color.TRANSPARENT));
stage.initOwner(parent);
stage.setX(parent.getX() + parent.getScene().getWidth() / 2d - width / 2d);
stage.setY(parent.getY() + parent.getScene().getHeight() / 2d - height / 2d);
parent.xProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
stage.setX(newValue.doubleValue() + parent.getScene().getWidth() / 2d - width / 2d);
}
});
parent.yProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
stage.setY(newValue.doubleValue() + parent.getScene().getHeight() / 2d - height / 2d);
}
});
} else {
stage.setScene(new Scene(root, width, height, Color.TRANSPARENT));
}
return stage;
}