Dynamically add CSS stylesheets in JavaFX

前端 未结 5 699
我寻月下人不归
我寻月下人不归 2021-01-05 11:08

I would like to add a CSS file which is located somewhere on the filesystem. The purpose is to write an application where the user can add JavaFX CSS files (which are create

5条回答
  •  悲&欢浪女
    2021-01-05 11:21

    You can get the URL from java.io.File

    File file = new File("style.css");
    URL url = file.toURI().toURL();
    scene.getStylesheets().add(url.toExternalForm());
    

    or in short form

    scene.getStylesheets().add((new File("style.css")).toURI().toURL().toExternalForm());
    

提交回复
热议问题