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;
}