如何圆化 JavaFX PopupControl 的角

Rob*_*275 1 java javafx popup popupwindow

我想稍微圆化 JavaFX PopupControl 的角。

下面是我尝试过的简单重现:

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage stage) {

    PopupControl pu = new PopupControl();
    pu.setStyle("-fx-background-radius: 10 10 10 10");
    pu.setStyle("-fx-border-radius: 10 10 10 10");

    VBox vb = new VBox();
    vb.setPrefWidth(300);
    vb.setPrefHeight(200);
    vb.setStyle("-fx-background-color: rgba(17, 230, 120, 1.0)");

    pu.getScene().setRoot(vb);
    stage.setWidth(600);
    stage.setHeight(500);
    stage.show();

    pu.show(stage);
Run Code Online (Sandbox Code Playgroud)

以下是所显示的内容:

为了澄清起见,绿色 PopupControl 的角是我试图修整的角。

任何帮助表示赞赏。

Jam*_*s_D 5

请注意,样式是单个属性,因此当您调用pu.setStyle(...)两次时,第二个样式将替换前一个样式;它不会增加它。

您需要在设置背景颜色的同一容器上设置背景半径。以下作品:

public void start(Stage stage) {

    PopupControl pu = new PopupControl();

    VBox vb = new VBox();
    vb.setPrefWidth(300);
    vb.setPrefHeight(200);
    vb.setStyle("-fx-background-color: rgba(17, 230, 120, 1.0); " +
            "-fx-background-radius: 10 10 10 10 ;");


    pu.getScene().setRoot(vb);
    stage.setWidth(600);
    stage.setHeight(500);
    stage.show();

    pu.show(stage);
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在外部样式表中设置样式是首选,而且可能更容易。