【发布时间】:2015-10-29 17:53:59
【问题描述】:
我正在尝试将 Java Fx 8 中的新 Dialog 类用于模态对话框,该对话框具有 圆角,显示时位于主舞台上方。
我有以下代码:
Dialog dialog = new Dialog<>();
Stage dialogStage = (Stage) dialog.getDialogPane().getScene().getWindow();
dialogStage.initStyle(StageStyle.TRANSPARENT);
DialogPane dialogPane = dialog.getDialogPane();
dialogPane.setStyle("-fx-background-radius: 15 15 15 15;fx-background-color:
transparent;-fx-border-radius: 0 0 0 0;");
dialogPane.getStylesheets().add(getClass().getResource("dialogstyle.css").toExternalForm());
dialogPane.getStyleClass().add("myDialog");
dialog.setTitle("Dialog Example");
dialog.setHeaderText("This is a custom dialog.");
dialog.setResizable(true);
Label label1 = new Label("Name: ");
Label label2 = new Label("Phone: ");
TextField text1 = new TextField();
TextField text2 = new TextField();
GridPane grid = new GridPane();
grid.add(label1, 1, 1);
grid.add(text1, 2, 1);
grid.add(label2, 1, 2);
grid.add(text2, 2, 2);
dialog.getDialogPane().setContent(grid);
ButtonType buttonTypeOk = new ButtonType("Okay", ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().add(buttonTypeOk);
加上隐藏和显示对话框等的代码
我已经结合了以下 css 样式表:
.myDialog{
-fx-background-color:rgba(0, 0, 0, 0);
-fx-background-radius: 15 15 0 0;
-fx-background-insets: 0, 1, 2;
-fx-border-radius: 0 0 0 0;
}
.myDialog > *.button-bar > *.container{
-fx-background-color: #a9e200;
-fx-background-radius: 0 0 15 15;
}
.myDialog > *.label.content{
-fx-font-size: 14px;
-fx-font-weight: bold;
}
.myDialog:header *.header-panel{
-fx-background-color: #a59c31;
-fx-background-radius: 15 15 0 0;
}
.myDialog:header *.header-panel *.label{
-fx-font-size: 18px;
-fx-font-style: italic;
-fx-fill: #292929;
}
这是基于the following post。
这很接近,但生成的对话框有白色的硬边,看起来是 场景。
添加
dialogPane.getScene().setFill(Color.TRANSPARENT);
有效,但使包含文本框的内容区域也透明。
任何人都可以建议我缺少什么以使其正常工作吗?
【问题讨论】:
标签: javafx-8