在JavaFX CSS中指定外部字体 [英] Specifying external font in JavaFX CSS
问题描述
是否可以在JavaFX应用程序中使用CSS指定字体?我有一个FXML场景和相应的CSS文件。在Java代码中,可以使用 setFont
方法指定字体:
text.setFont(Font.loadFont(file:resources / fonts / SourceSansPro-Bold.ttf,12));
我尝试了不同的结构,例如:
-fx-font-family:url(../ fonts / SourceSansPro-Bold.ttf);
但是不行。
您已经接近解决方案:
$ b
-fx-font-family:'Helvetica',Arial,sans-serif;
试试这个吧,它应该可以正常工作。
< hr>
也许这可能有帮助? (我不是JavaFX的专家)
https://forums.oracle.com/forums/thread.jspa?messageID=10107625
$ b lang-css prettyprint-override>
@ font-face {
font-family:Delicious;
src:url('Delicious-Roman.otf');
$ b 在 -fx -
-fx-font-family:'Delicious';
Is it possible to specify a font using CSS in JavaFX application? I have an FXML scene and the corresponding CSS file. In Java code, it's possible to specify a font using the setFont
method:
text.setFont(Font.loadFont("file:resources/fonts/SourceSansPro-Bold.ttf", 12));
I tried different constructions, like:
-fx-font-family: url("../fonts/SourceSansPro-Bold.ttf");
but it doesn't work.
解决方案 You were close to the solution:
-fx-font-family: 'Helvetica', Arial, sans-serif;
Try this, it should work fine.
Maybe this could help? (I'm not an expert in JavaFX)
https://forums.oracle.com/forums/thread.jspa?messageID=10107625
EDIT:
Load your font:
@font-face {
font-family: Delicious;
src: url('Delicious-Roman.otf');
}
Use your font with -fx-
:
-fx-font-family: 'Delicious';
这篇关于在JavaFX CSS中指定外部字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!