Specifying external font in JavaFX CSS

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

    Another way is to load font using FileIUnputStream, thus you don't need to use css:

     @FXML
        private Label myLabel;
    
    @Override
        public void initialize(URL arg0, ResourceBundle arg1){
    
    Font myFont = null;
    
            try {
                myFont = Font.loadFont(new FileInputStream(new File("patch_to_font.ttf")), 10);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
    
            myLabel.setFont(myFont);
    
    }
    

提交回复
热议问题