I was following the instructions given in the correct answer in this post.
Javafx How to display custom font in webview?
The font file is located at the same package as the Main class.
This is my full code.
package sample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class Main extends Application{
public void start(Stage primaryStage) throws Exception{
Font.loadFont(Main.class.getResource("TRON.TTF").toExternalForm(),10);
StackPane pane = new StackPane();
Label label = new Label("Text");
pane.getChildren().add(label);
label.setStyle("-fx-font-family:'TRON'; -fx-font-size: 50px;-fx-text-fill: red");
Scene scene = new Scene(pane,300,300);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Output
The font color and the font size has been affected. But the Tron font family has not been used.
I downloaded the font ttf file from here.