【问题标题】:JavaFX: How not to fill background outside the rounded borders of a Label within a ScrollingPaneJavaFX:如何不填充 ScrollingPane 内标签的圆形边框之外的背景
【发布时间】:2016-07-19 03:40:20
【问题描述】:

我试图在 ScrollingPane 内的标签上获得圆角边框,但标签的背景填充仍然显示为矩形,即使边框是圆角的。如何确保背景填充符合 Label 的圆角边框?

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;
}

【问题讨论】:

  • 您是否尝试将-fx-background-radius-fx-border-radius 匹配?另请参阅JavaFX CSS Reference

标签: java css javafx


【解决方案1】:

感谢@sillyfly 指出 -

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

【讨论】:

    【解决方案2】:

    设置标签透明背景色

    -fx-background-color: transparent;
    

    【讨论】:

    • 这不是我想要的,因为我仍然想要背景颜色
    猜你喜欢
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 2020-04-16
    • 2016-05-24
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    相关资源
    最近更新 更多