簡體   English   中英

JavaFX嵌入自定義字體不起作用

[英]JavaFX Embed Custom Font Not Working

我正在使用JavaFX版本8.0.40-b27,並嘗試通過CSS嵌入自定義/外部字體。 我也嘗試過編程方法,但都失敗了。 “字體”的System.out.print返回null,我懷疑是原因。

Java的:

 Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "application/stratum.ttf"), 10); System.out.println(font); // Prints "null" nowPlayingTitle.setFont(font); 

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

目錄: http //i.stack.imgur.com/c92ii.png

編輯: System.out.println(font); 現在將輸出Font [name = StratumNo1-Thin,family = StratumNo1,style = Thin,size = 10.0] ,因此可以正確訪問文件。 但是,該字體仍未在屏幕上呈現: http : //i.stack.imgur.com/bueUk.png

對於Java代碼中的URL,請嘗試

// relative to classpath, with leading /
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "/application/stratum.ttf"), 10);

要么

// relative to class:
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "stratum.ttf"), 10);

CSS對我來說似乎正確...您確定將ttf文件與編譯后的代碼作為css等一起部署嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM