0

So I have multiple '.ttf' fonts in a folder buy I'm failing to use them in scene builder using fxml and CSS.

Here's what I've tried with a label called 'serial connection' attached to a CSS file with theses lines:

.serialConn {
    -fx-font-family:URL("fonts/capsuula.ttf");
}

That's similar to what I'm using to set backgrounds but obviously doesn't work for fonts.

John Slegers
  • 45,213
  • 22
  • 199
  • 169
ron weasly
  • 89
  • 2
  • 14

1 Answers1

3

This should work for Java versions < 1.8u60 :

@font-face {
    font-family: 'Capsuula';
    src: url('fonts/capsuula.ttf');
}

.serialConn {
    -fx-font-family: 'Capsuula';
}

Note :

Make sure that the value of -fx-font-family (Capsuula in my code example) is the actual name of the font as it is found inside capsuula.ttf.

For more info, you can go to How to integrate custom fonts in your JavaFX application by using CSS

John Slegers
  • 45,213
  • 22
  • 199
  • 169
  • Thanks, but its not working at least in scene builder (sorry...should have mentioned earlier!). I've tried something similar when I was creating a webpage - works fine but not in scene builder or fxml. By the way, my desktop app should work fine offline so I have the '.ttf' files in a folder on my pc. – ron weasly Jan 24 '16 at 18:46
  • @tpmabb : This SHOULD work. Are you sure the font file has the right file permissions? Are you sure the path to the font file is the correct path? Note that the path should be relative to the location of the CSS file where you put your `@font-face {font-family: Capsuula; src: url('path/to/capsuula.ttf');}` – John Slegers Jan 24 '16 at 18:56
  • Typed in exactly as you demonstrated. I use a folder called imageBackgrounds to set my backgrounds and it works...the fonts folder is next to the backgrounds one so I know the path is correct unless fonts use a different structure... – ron weasly Jan 24 '16 at 19:03
  • @tpmabb : Make sure that the value of `-fx-font-family` is IDENTICAL actual name of the font as it is found inside file `capsuula.ttf`. – John Slegers Jan 24 '16 at 19:08
  • I opened the ttf' and noticed the only difference was a capital C and fixed that but still no luck...I'm playing around with the punctuation marks but... – ron weasly Jan 24 '16 at 19:18
  • Hey thanks. Are you in a position to maybe try it out maybe I'm messing up somewhere? – ron weasly Jan 24 '16 at 19:22
  • @tpmabb : Unfortunately I'm not :-( – John Slegers Jan 24 '16 at 19:26
  • It's cool. From my research you are right but its not working...I will just use java code later on as suggested here: http://stackoverflow.com/a/16866962/3405611 . Thanks! – ron weasly Jan 24 '16 at 19:29