1

I know this is old, but it is just not working with me, already checked :

JavaFX custom Fonts

and

How to embed .ttf fonts is JavaFx 2.2?

digital-clock.css :

@font-face {
font-family: 'DINRegular';
src: url('../fonts/DINRegular.tff'); // also tried url('/fonts/DINRegular.tff'); and url('fonts/DINRegular.tff'); 
}

.label {
    -fx-font-family: 'DINRegular';
    -fx-font-size: 30;
}

.button .text {
    -fx-font-family: 'DINRegular';
}

loading the css with :

getStylesheets().add(getClass().getResource("/style/digital-clock.css").toExternalForm());

resources

loading font programatically doesnt work either :

example :

public static javafx.scene.text.Font loadFont(String name) {
    return javafx.scene.text.Font.loadFont(FXMLConstants.class.getResource("/fonts/"+"digital"+".ttf").toExternalForm(), 12);
}

enter image description here

enter image description here

enter image description here

Community
  • 1
  • 1
Abdullah Asendar
  • 574
  • 1
  • 5
  • 31
  • What does the tree of your compile target directory look like? Or the contents of the jar file `jar tvf `? – jewelsea Jun 18 '16 at 18:14
  • 1
    Note, there was a report that the [font-family attribute of @font-face is ignored in Java 8u60](http://www.guigarage.com/2014/10/integrate-custom-fonts-javafx-application-using-css/). Maybe open your font in some kind of true type viewer application and verify that the name embedded in the font is reapply `DINRegular`, as whatever name you use must match whatever is in the font file. – jewelsea Jun 18 '16 at 18:22
  • 3
    Note that if you package your application as a jar, the `..` specifier will not work when you load the CSS using getResource, as the `jar:` protocol used by the [JavaFX CSS `` type](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typeurl) does not process `..` parent directory specifiers. Still, the absolute path `/fonts/DINRegular.ttf` should have resolved correctly if the file is in the target directory or jar file. – jewelsea Jun 18 '16 at 18:36
  • @jewelsea thank you,, kindly check the edited answer ? its kinda weird – Abdullah Asendar Jun 18 '16 at 20:19

0 Answers0