Specifying external font in JavaFX CSS

后端 未结 5 641
天涯浪人
天涯浪人 2020-12-08 15:52

Is it possible to specify a font using CSS in JavaFX application? I have an FXML scene and the corresponding CSS file. In Java code, it\'s possible to specify a font using t

5条回答
  •  悲&欢浪女
    2020-12-08 16:43

    JavaFx CSS fonts (import .ttf):

    /* import fonts */
    @font-face {
        font-family: "Open Sans";
        font-style: normal;
        font-weight: 400;
        src: url("/fonts/OpenSans-Regular.ttf");
    }
    @font-face {
        font-family: "Open Sans Light";
        font-style: normal;
        font-weight: 300;
        src: url("/fonts/OpenSans-Light.ttf");
    }
    @font-face {
        font-family: "Open Sans Bold";
        font-style: normal;
        font-weight: 700;
        src: url("/fonts/OpenSans-Bold.ttf");
    }
    @font-face {
        font-family: "Open Sans ExtraBold";
        font-style: normal;
        font-weight: 900;
        src: url("/fonts/OpenSans-ExtraBold.ttf");
    }
    
    /* Set fonts */
    
    .settings-name{
        -fx-font-size: 33px;
        -fx-font-family: "Open Sans Light";
        -fx-font-weight: 300;
        -fx-text-fill: #09f;
    }
    
    .settings-username{
        -fx-font-size: 19px;
        -fx-font-family: "Open Sans ExtraBold";
        -fx-font-weight: 900;
        -fx-text-fill: #09f;
    }
    

提交回复
热议问题