Note that the below will work only with Java versions >= 1.8u60
我遇到了同样的问题.在JavaFX 8中加载CSS的方法是设置字体表面文件,然后使用字体名称作为参考,可以通过预览字体找到.
字体文件相对于CSS.我有根设置字体,但您可以删除它并保留每个节点.
CSS code
@font-face {
src: url("freeuniverse2.ttf"),
}
.root {
-fx-background-color: gray;
-fx-font-family: "Free Universe 2";
}
#window {
-fx-border-image-source: url("images/windowfill.png");
-fx-border-image-slice: 17 6 13 6 fill;
-fx-border-image-width: 17 6 13 6 ;
-fx-background-color: gray;
}
.text {
-fx-text-fill: white;
-fx-font-size: 16px;
-fx-font-family: "Free Universe 2";
-fx-background-color: transparent;
}
.pane {
-fx-border-image-source: url("images/windowfill.png");
-fx-border-image-slice: 17 6 13 6 fill;
-fx-border-image-width: 17 6 13 6 ;
-fx-background-color: gray;
}
.vbox {
-fx-border-image-source: url("images/windowfill.png");
-fx-border-image-slice: 17 6 13 6 fill;
-fx-border-image-width: 17 6 13 6 ;
-fx-background-color: gray;
}
#title-text {
-fx-text-fill: white;
-fx-font-size: 36px;
-fx-font-family: "Free Universe 2";
}
.label {
-fx-text-fill: white;
-fx-font-size: 16px;
-fx-font-family: "Free Universe 2";
-fx-background-color: transparent;
}
Font File Preview(Below you can see the real Font Name)