I am trying to center a Popup in the center of a Stage, but I can't do it right because I need the size of the Popup and it is coming as size 0 (popup.getWidth()=0 and popup.getHeight()=0).
How to get the correct size?
My code is below:
Popup popup = new Popup();
popup.setAutoFix(true);
popup.setAutoHide(true);
popup.setHideOnEscape(true);
Label label = new Label("Empty indentation char!");
label.setOpacity(100);
label.setStyle("-fx-background-color: cornsilk;");
popup.getContent().add(label);
Point2D center = Utils.getCenter(mainClass.getOptionsStage());
popup.show(mainClass.getOptionsStage(),
center.getX() - popup.getWidth() / 2,
center.getY() - popup.getHeight() / 2);
- Utils.getCenter() returns the center point of a window.