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:
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:
Use your font with
-fx-: