Custom Font with JavaFX SceneBuilder


JavaFX's SceneBuilder is very useful, but I want to add a custom font to it. In the past, this has worked, though I have no idea how. Screenshot:

enter image description here

Minecraftia is not in SceneBuilder as a default font, but it worked when I defined the Minecraftia font in CSS. I tried doing the same with the new font i want (Roboto), but it doesn't show up in SceneBuilder. I know that i could style the labels in CSS, but I liked it better when the font popped up in SceneBuilder. Does anyone know why/how custom fonts show up in SceneBuilder?

6/18/2018 7:50:54 AM


Since Java 8 JavaFX supports the @font-face rule that can be used to add fonts. As a first step the font file must be added to the application.

Once this is done the font can be defined in CSS by using the @font-face rule: in your case

@font-face {
    font-family: 'Roboto';
    src: url('Roboto-Medium.ttf');

.text {
    -fx-font-family: "Roboto";

check this blog and a answer for more information.

5/23/2017 12:31:45 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow