gpt4 book ai didi

java - 如何使弹出窗口居中?

转载 作者:行者123 更新时间:2023-12-02 13:19:51 24 4
gpt4 key购买 nike

所以我在弹出窗口中使用 jfoenix JFXPopup 组件。最终显示弹出窗口后。我意识到弹出窗口是相对于您传递的所有者节点显示的。我的问题是有什么方法可以显示相对于场景的弹出窗口,以便我可以将其居中吗?

不幸的是,您无法将弹出窗口置于所有者节点的中心,您只能将其上下或左右移动?

Popup relative to the search textfield in the middle of the application

//Current Code
@FXML
protected void handleLoginButton(ActionEvent event) {
System.out.println("Popup BUtton clicked");
if (!loginPopup.isShowing()) {
System.out.println("Popup is open!");
//loginPopup.show(searchBtn, JFXPopup.PopupVPosition.BOTTOM, JFXPopup.PopupHPosition.LEFT);
loginPopup.show(searchBtn);
}
}

最佳答案

调用show时使用场景的根 Pane ,并计算中心位置;

popupRoot.setPrefWidth(200);
popupRoot.setPrefHeight(300);
button.setOnAction(event -> {
JFXPopup loginPopup = new JFXPopup(popupRoot);
Bounds rootBounds = scene.getRoot().getLayoutBounds();
loginPopup.show(scene.getRoot(), JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT,
(rootBounds.getWidth() - popupRoot.getPrefWidth()) / 2,
(rootBounds.getHeight() - popupRoot.getPrefHeight()) / 2);
});

参见here从 Controller 访问场景。

关于java - 如何使弹出窗口居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43617772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com