Specifying external font in JavaFX CSS

后端 未结 5 642
天涯浪人
天涯浪人 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:29

    Just found out one more detail: In JavaFX-8 if you want to have regular and bold variants of the same font you can specify them with two instances of @font-face. Then you can use -fx-font-weight: bold;

    @font-face {
        font-family: 'Droid Sans';
        src: url('DroidSans.ttf');
    }
    
    @font-face {
        font-family: 'Droid Sans Bold';
        src: url('DroidSans-Bold.ttf');
    }
    
    .root {
        -fx-font-family: 'Droid Sans'; 
    }
    
    .table-row-cell:focused .text {
        -fx-font-weight: bold;
    }
    

提交回复
热议问题