Setting background image by javafx code (not css)

前端 未结 2 2041
攒了一身酷
攒了一身酷 2021-01-04 22:23

I\'m trying to set an image as the background using this code:

root.setStyle(\"-fx-background-image: url(\'splash.jpg\'); 
               -fx-background-posi         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 23:24

    Try next:

    String image = JavaFXApplication9.class.getResource("splash.jpg").toExternalForm();
    root.setStyle("-fx-background-image: url('" + image + "'); " +
               "-fx-background-position: center center; " +
               "-fx-background-repeat: stretch;");
    

提交回复
热议问题