小编cob*_*798的帖子

JavaFX CSS“找不到资源”

当我尝试更改 css 文件所在的文件夹时,出现此错误:

WARNING: com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged Resource "file:/C:/[path-to-project]/Test/resources/css/main.css" not found.
Run Code Online (Sandbox Code Playgroud)

我复制了 URL 并将其粘贴到文件管理器中,然后它打开了文件,所以我知道它存在。

public static void main(String[] args)
{
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception
{
    primaryStage.setTitle("New Window");

    Scene scene = new Scene(new AnchorPane(), 800, 600);
    primaryStage.setScene(scene);

    URL css = new URL("file:///" + 
            new File("resources/css").getAbsolutePath().replace("\\", "/") + 
            "/main.css");
    scene.getStylesheets().clear();
    scene.getStylesheets().add(css.toExternalForm());

    primaryStage.show();
}
Run Code Online (Sandbox Code Playgroud)

这是我的 Eclipse 项目布局[也作为图像]

public static void main(String[] args)
{
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception
{
    primaryStage.setTitle("New Window");

    Scene scene …
Run Code Online (Sandbox Code Playgroud)

css java javafx classpath

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

classpath ×1

css ×1

java ×1

javafx ×1