Search code examples
javafx-2javafxjavafx-8

Set Font globally in JavaFX


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.


Solution

  • 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());