JavaFX:如何不在 ScrollingPane 中的标签的圆形边框之外填充背景

标签 java css javafx

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

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

最佳答案

感谢@sillyfly 指出 -

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

关于JavaFX:如何不在 ScrollingPane 中的标签的圆形边框之外填充背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38449219/

相关文章:

JavaFX 客户端 UI 不会显示主机触发的警报

java - Eclipse 在 Maven 项目中按字母顺序对文件夹进行排序

java - 在 Java 中使用 do-while 循环检查用户的输入

java - 使用时间戳会导致 WSDL 生成出现问题

jquery - 如何从每一侧向其中心缩小一个 div 而不是从右向左

jquery - 类没有在焦点上被删除 - jQuery

java - 每次打开 eclipse 时都必须打开模拟器 3 次才能让应用程序运行

angular - Flex 布局高度问题

java - 如何在 JavaFX 中为窗口添加阴影?

javafx - 在 JavaFX 8 中使用来自另一个表单/ Controller 的控件