Set Font globally in JavaFX

Peter Penzov picture Peter Penzov · Aug 23, 2013 · Viewed 23.9k times · Source

How can I set the Font type globally in a JavaFX application?

Is there any solution that I can use? In JavaFX 8 the default Font has changed, and I would like to use the same Font used in JavaFX 2.2.

Answer

nyyrikki picture nyyrikki · Aug 23, 2013

You can skin your application with CSS as described on the Oracle Website. Using following syntax you may set the general theme for your application:

.root{
    -fx-font-size: 16pt;
    -fx-font-family: "Courier New";
    -fx-base: rgb(132, 145, 47);
    -fx-background: rgb(225, 228, 203);
}

You include the css as followed:

scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());