JavaFX:如何在滚动面板中的标签的圆角边框外部不填充背景。

3

我正在尝试在滚动窗格内的标签上获得圆角边框,但即使边框是圆角的,标签的背景填充仍然呈矩形。如何确保背景填充符合标签的圆角边框?

Fills outside of rounded borders

Java:

String quizMetaData = quiz.getQuizMetadata();

Label quizInfoText = new Label(quizMetaData);
ScrollPane scrollPane = new ScrollPane();

quizInfoText.setId("quiz-info-text");
quizInfoText.prefWidthProperty().bind(scrollPane.widthProperty().multiply(0.95));
quizInfoText.prefHeightProperty().bind(scrollPane.heightProperty().multiply(0.98));

scrollPane.setContent(quizInfoText);
scrollPane.setId("quiz-info-scrollpane");
scrollPane.setPrefSize(600, 250);
scrollPane.setLayoutX(100);
scrollPane.setLayoutY(60);
pane.getChildren().add(scrollPane);

CSS:

#quiz-info-text {
    -fx-background-color: #203020;
    -fx-font: 16pt "Courier New";
    -fx-text-fill: #00C030;
    -fx-alignment: top-center;
    -fx-border-width: 10;
    -fx-border-color: #306030;
    -fx-border-radius: 15.0;
    -fx-padding: 1;
    -fx-wrap-text: true;
}

#quiz-info-text:hover {
    -fx-background-color: #304030;
    -fx-font: 16pt "Courier New";
    -fx-text-fill: #00E020;
    -fx-alignment: top-center;
    -fx-border-width: 10;
    -fx-border-color: #306030;
    -fx-border-radius: 15.0;
    -fx-padding: 1;
    -fx-wrap-text: true;
}

#quiz-info-scrollpane {
    -fx-background: #000000;
    -fx-fit-to-width: true;
    -fx-fit-to-height: false;
    -fx-vbar-policy: as-needed;
    -fx-hbar-policy: as-needed;
    -fx-border-color: #000000;
    -fx-background-color: black;
}

#quiz-info-scrollpane:focused {
    -fx-border-color: #000000;
    -fx-background-color: black;
}

2
你尝试过将“-fx-background-radius”与“-fx-border-radius”匹配吗?另请参阅JavaFX CSS参考 - Itai
2个回答

6

感谢@sillyfly的指出 -

我在CSS中忘记了添加-fx-background-radius: 15


0

将标签的背景颜色设置为透明

-fx-background-color: transparent;

这不是我想要的,因为我仍然想要背景颜色。 - euwbah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接