gpt4 book ai didi

javafx - 如何在 Javafx 中对齐对话框 Pane 的确定按钮?

转载 作者:行者123 更新时间:2023-12-04 15:09:21 25 4
gpt4 key购买 nike

我想对齐,即定位 CENTER DialogPane 的 OK 按钮。我已经尝试了下面的代码,但它不起作用。

Dialog dialog = new Dialog();
DialogPane dialogPane = dialog.getDialogPane();
dialogPane.setStyle("-fx-background-color: #fff;");

// Set the button types.
ButtonType okButtonType = new ButtonType("Ok", ButtonBar.ButtonData.OK_DONE);
ButtonType cancelButtonType = new ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
dialog.getDialogPane().getButtonTypes().addAll(okButtonType, cancelButtonType);
dialogPane.lookupButton(cancelButtonType).setVisible(false);

// Testing
Button okButton = (Button) dialog.getDialogPane().lookupButton(okButtonType);
okButton.setAlignment(Pos.CENTER);
// End Testing

dialog.showAndWait();

最佳答案

我试图在 Alert 中居中确定按钮而且我不确定这是错误还是功能(Java8),但可以通过设置新按钮来居中单个按钮:

alert.getButtonTypes().set(0, new ButtonType("OK", ButtonBar.ButtonData.LEFT));

只要只有一个带有 ButtonData.LEFT的按钮,它位于按钮面板的中间。显然,此解决方案不适用于具有多个按钮的面板,但它可能有助于定位单个 OK 按钮。

关于javafx - 如何在 Javafx 中对齐对话框 Pane 的确定按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36009764/

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