ファイルシステムのどこかにある CSS ファイルを追加したいと思います。目的は、ユーザーが (誰でも作成し、どこにでもある) JavaFX CSS ファイルを動的に追加できるアプリケーションを作成することです。
動的に追加されたCSSファイルが機能するかどうかを確認するために、テストのためだけに、そのようなことを試しました:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Label label = new Label("Hello");
Scene scene = new Scene(label);
//file would be set by an file chosser
File file = new File("C:/test.css");
scene.getStylesheets().add(file.getAbsolutePath());
primaryStage.setTitle("Title");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
しかし、私は常に同じエラーが発生します:
WARNING: com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged Resource "C:\test.css" not found.
どうすれば修正できますか?