adding css file to stylesheets in javafx

前端 未结 18 1349
[愿得一人]
[愿得一人] 2020-12-06 05:27

Language: JavaFX

IDE: Netbeans

Problem: I\'m trying to add a css file to the stylesheet, but the first line of the following code always generates a Nu

18条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 05:42

    I made a small login example and this is how i link my styleshet.css

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("LoginUI.fxml"));
    
    
        Scene scene = new Scene(root);
    
        scene.getStylesheets().add(JavaFXLogin.class.getResource("stylesheet.css").toExternalForm());
    
        stage.setScene(scene);
        stage.show();
    
    }
    

    You can use this code line to link your css file. but the css file should be in your package.

    scene.getStylesheets().add(JavaFXLogin.class.getResource("stylesheet.css").toExternalForm());

提交回复
热议问题