Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 360
Peter Penzov Avatar asked Aug 23 '13 17:08

Peter Penzov


People also ask

What is the default Font for Javafx?

There is a Segoe UI as default Font on your Windows 7 system, but the version is 5.01 per default.

How do I change the Font size in Javafx text?

You can change the font size and color of the text using the setFont() method. This method accepts an object of the Font class. The class named Font of the package javafx.


1 Answers

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());
like image 121
nyyrikki Avatar answered Oct 15 '22 07:10

nyyrikki