java弹出窗口宽度和高度=0
我试图将一个弹出窗口放在舞台中央,但我做不好,因为我需要弹出窗口的大小,它的大小是0(Popup.getWidth()=0,Popup)。getHeight()=0)
如何获得正确的尺寸
我的代码如下:
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);
- 乌提尔斯。getCenter()返回窗口的中心点李>
# 1 楼答案
Popup
直到他被展示出来才知道他的界限在显示后尝试移动它: