我需要将文件 style.css 作为样式表添加到场景中。 我试图在 ScreenController 类中执行此操作,该类位于 justAnotherChessGame.model 包中。 该文件位于同一目录中,但位于不同的包中。 如何找到相对路径? Project structure
最佳答案
如果您的场景是 sc
并且 Pane 是 ScreenController
中的 p
,
Scene sc = new Scene(p, 400, 300);
sc.getStylesheets().add("/justAnotherChessGame/view/style.css");
primaryStage.setScene(sc);
您需要研究this案例。
关于JAVAFX:找不到文件的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51918751/