【发布时间】:2020-08-04 05:28:08
【问题描述】:
我是 Javafx 的新手,正在尝试为用户实现警告/确认对话框。
我可以得到对话框,但无法按要求对齐。
现在,我需要进行两项更改,
- 我想要并排放置按钮,首先是yes,然后是no。但默认情况下应选择“否”。这样在关闭时 No 作为响应发送。
- 我想在文本和按钮之间留出一些空间。如果文本大小增加,是否可以将文本分成两行?
以下是我当前的代码:
public static boolean display(String title, String message){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Confirmation");
window.setMinWidth(540);
window.setMinHeight(250);
Label label = new Label();
label.setText(message);
Button yesButton = new Button("Yes");
Button noButton = new Button("no");
yesButton.setOnAction(e->{
answer = true;
window.close();
});
noButton.setOnAction(e->{
answer = false;
window.close();
});
VBox layout = new VBox(10);
layout.getChildren().addAll(label,noButton,yesButton);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
return answer;
}
请帮忙。提前致谢。
【问题讨论】:
-
完成布局教程