Javafx css font style

How to integrate custom fonts in your JavaFX application by using CSS

This is one of the CSS tips that were part of my “Extreme Guimaker” talk at JavaOne this year and will show how you can change the font for a complete application or only a specific control by using CSS.

Before explaining the CSS solution I want to show a short example in Java code:

font

Now the font will be used in our application even if it isn’t installed on the OS:

font-loaded

Update

As I learned today the shown code isn’t working in Java versions >= 1.8u60. Starting with this version the attribute “font-family” is ignored and you have to use the real name of the TTF.

If you want to use the font “Birds of Paradis” that is contained in the file demo.ttf , for example, you have to use this CSS file:

@font-face  src: url(“/ui/font/demo.ttf”); > .label  -fx-font-family: Birds of Paradise; >
Author

Hendrik Ebbers is a co-founder of Karakun AG and lives in Dortmund, Germany. He is the founder and leader of the Java User Group Dortmund and gives talks and presentations in user groups and conferences. His JavaFX book «Mastering JavaFX 8 Controls» was released 2014 by Oracle press. Hendrik is JavaOne Rockstar, JSR expert group member and Java Champion.

Источник

Читайте также:  Java or operator char
Оцените статью