【问题标题】:Java Fx 8 Dialog rounded cornersJava Fx 8 对话框圆角
【发布时间】: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


    【解决方案1】:

    以防万一有人仍然需要这样做,我通过这样做设法在 JFXDialog 上设置了圆角:(以及添加背景半径 tpo 根元素)

    .jfx-dialog-overlay-pane > StackPane{
    -fx-background-radius: 20;
    -fx-background-color: white; 
    }
    

    我没有尝试过使用对话框,但我猜解决方案几乎相同。

    【讨论】:

      猜你喜欢
      • 2017-12-28
      • 2015-03-14
      • 1970-01-01
      • 2016-07-18
      • 2013-05-27
      • 2019-12-11
      • 2012-04-11
      • 2016-12-05
      相关资源
      最近更新 更多