Specifying external fonts in JavaFX CSS

Can I use CSS to specify fonts in JavaFX applications? I have an fxml scenario and the corresponding CSS file In Java code, you can use the SetFont method to specify a font:

text.setFont(Font.loadFont("file:resources/fonts/SourceSansPro-Bold.ttf",12));

I have tried different structures, such as:

-fx-font-family: url("../fonts/SourceSansPro-Bold.ttf");

But it can't

Solution

You are close to the solution:

-fx-font-family: 'Helvetica',Arial,sans-serif;

Try this, it should work properly

Maybe this can help? (I'm not an expert on JavaFX)

https://forums.oracle.com/forums/thread.jspa?messageID=10107625

Edit:

Load your font:

@font-face {
    font-family: DelicIoUs;
    src: url('DelicIoUs-Roman.otf');
}

Use your font with - FX -:

-fx-font-family: 'DelicIoUs';
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>