Dynamically add CSS stylesheets in JavaFX

前端 未结 5 727
我寻月下人不归
我寻月下人不归 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:27

    The exception is thrown because the string "C:/test.css" is not a URI resource. Therefore you must convert your string into a URI resource.

    As of Java 7 you can do:

    String uri = Paths.get("C:/test.css").toUri().toString();
    scene.getStylesheets().add(uri);
    

提交回复
热议问题