0

When I make javafx load a font with a code like this:

font = Font.loadFont(getClass().getClassLoader().getResource("gui/font.ttf").toExternalForm(), 25);

and, after it has successfully loaded, apply it to a Text

text.setFont(font);

the text shows the right font BUT, when I try to apply to it some styles or weights like

text.setStyle("-fx-font-weight: bold;");

or

text.setStyle("-fx-font-style: italic;");

Nothing changes. I've tried this even with the SceneBuilder and It doesn't work there too. What can I do to make java load my font WITH all the styles and weights (or, at least, make it try to derive them)?

EDIT: fount used: Peque Script (I know, 5 minutes ago it wasn't in maintenance) Some other fonts found online like this or this

SnowyCoder
  • 213
  • 7
  • 18

1 Answers1

0

I tried with a random one and is working, i think it is due to the Font that you use, it may not have a weight, what Font you are using ? (can't comment).

Edit : i've done a little research, and i've found that only one (individual/united) Style is present in a ".tff" file even if it's a rich file. If you take the example of "consolas" Font, there is 4 types (Normal/Italic/Bold/Bold-Italic), these types are used together but in separate files. I hope this answered your question.

Bo Halim
  • 1,716
  • 2
  • 17
  • 23
  • 1
    Yes but in java.awt.Font there is something to derive fonts, and it is in every other normal api/application, isn't there any way to derive bold or italic? (even if it should do it on his own) – SnowyCoder Nov 22 '16 at 06:18