如果要使用自訂的字體檔(系統沒有內建的字體),需要使用CSS的方式來達成。
1.將ttf字型檔丟到跟css檔案同一個資料夾中

2.在css style中載入字體檔
@font-face {
src: url("jf-openhuninn.ttf"),
}
3.新增字體樣式,需要連字型大小都設定,才不會造成顯示錯亂
.font18 {
-fx-font-family:"jf-openhuninn-1.1";
-fx-font-size:18px;
}
.font20 {
-fx-font-family:"jf-openhuninn-1.1";
-fx-font-size:20px;
}
.font22 {
-fx-font-family:"jf-openhuninn-1.1";
-fx-font-size:22px;
}
.font23 {
-fx-font-family:"jf-openhuninn-1.1";
-fx-font-size:23px;
}
.font24 {
-fx-font-family:"jf-openhuninn-1.1";
-fx-font-size:24px;
}
所以就會像這樣一堆字體大小
-fx-font-family為此字體的名稱,這個需要去查詢才知道
4.最後在fxml中使用他

記得在最外層載入css檔才看得到樣式選項喔!
-END-
發佈留言