以下是我在出现错误或警告时显示对话框的代码,但我无法对齐文本和按钮。这两件事互相覆盖。
//INITIALIZING SCENE FOR dialogStage
StackPane dialogStackPane = new StackPane();
dialogStackPane.setAlignment(Pos.CENTER);
dialogStackPane.setLayoutX(0);
dialogStackPane.setLayoutY(0);
dialogStackPane.setPrefWidth(250.0);
dialogStackPane.setPrefHeight(150.0);
// dialogStage height and width
dialogStage.setHeight(150.0);
dialogStage.setWidth(250.0);
//Scene for dialogStage
sceneDialog = new Scene(dialogStackPane, 150.0, 250.0);
sceneDialog.getStylesheets().add("/styles/Login.css");
// Dialog box button
btnDialog = new Button("close");
btnDialog.setMinSize(10.0, 20.0);
ObservableList ol = dialogStackPane.getChildren();
ol.add(textWarning);
ol.add(btnDialog);
textWarning.setX(0);
textWarning.setY(0);
btnDialog.setLayoutX(0);
btnDialog.setLayoutY(0);
// SETTING THE MODALITY OF THE DIALOG BOX
dialogStage.initModality(Modality.APPLICATION_MODAL);
dialogStage.setTitle("Warning");
dialogStage.setScene(sceneDialog);
// Setting event listener on warning dialogStage button b
btnDialog.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() {
// This handles the Mouse event of the dialog box button.
@Override
public void handle(MouseEvent t) {
if (t.getEventType() == MouseEvent.MOUSE_CLICKED) {
dialogStage.close();
}
}
});
textWarning.setLayoutX(20);
textWarning.setLayoutY(200);
// textWarning.setTextOrigin(VPos.TOP); // textWarning.setTextAlignment(TextAlignment.LEFT);
// Sets the warning box
dialogStage.setResizable(false);
任何帮助,将不胜感激。