I am looking to incorporate a CSS file from the filesystem into my application. The goal is to allow users to dynamically add JavaFX CSS files that can be created by anyone and stored anywhere on their system.
I attempted a test scenario to see if adding CSS files dynamically would work:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Label label = new Label("Hello");
Scene scene = new Scene(label);
//file path set by user using file chooser
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);
}
}
However, I encountered an error every time:
WARNING: com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged Resource "C:\test.css" not found.
What steps should I take to resolve this issue?