[英]JavaFX Embed Custom Font Not Working
I'm using JavaFX version 8.0.40-b27 and trying to embed a custom/external font via CSS. 我正在使用JavaFX版本8.0.40-b27,并尝试通过CSS嵌入自定义/外部字体。 I've also tried programmatic approaches, all of which have failed.
我也尝试过编程方法,但都失败了。 A System.out.print of "font" returns null, which I suspect to be the cause.
“字体”的System.out.print返回null,我怀疑是原因。
Java: Java的:
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "application/stratum.ttf"), 10); System.out.println(font); // Prints "null" nowPlayingTitle.setFont(font);
CSS: CSS:
@font-face { font-family: stratum; src: url('stratum.ttf'); } .text{ -fx-font-family: "stratum", "Segoe UI Light"; -fx-font-weight: 100; -fx-text-fill: white; }
Directory: http://i.stack.imgur.com/c92ii.png 目录: http : //i.stack.imgur.com/c92ii.png
EDIT: System.out.println(font); 编辑: System.out.println(font); now prints Font[name=StratumNo1-Thin, family=StratumNo1, style=Thin, size=10.0] , so the file is being accessed correctly.
现在将输出Font [name = StratumNo1-Thin,family = StratumNo1,style = Thin,size = 10.0] ,因此可以正确访问文件。 However the font is still not being rendered on screen: http://i.stack.imgur.com/bueUk.png
但是,该字体仍未在屏幕上呈现: http : //i.stack.imgur.com/bueUk.png
For the URL in Java code, try either 对于Java代码中的URL,请尝试
// relative to classpath, with leading /
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "/application/stratum.ttf"), 10);
or 要么
// relative to class:
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "stratum.ttf"), 10);
The CSS looks right to me... are you sure your ttf file is being deployed along with the compiled code as css, etc? CSS对我来说似乎正确...您确定将ttf文件与编译后的代码作为css等一起部署吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.