我创建了一个简单的 JavaFX
应用。
它有两个包,主类是 JFXTest2.java
在 good
包和 fxml 及其 Controller 在 JFXTest2
中包裹。
现在的问题是我无法在主类中加载 fxml。我尝试加载
fxml 像这样:
Parent root = FXMLLoader.load(getClass().getResource("jfxtest2.Screen.fxml"));
和
Parent root = FXMLLoader.load(getClass().getResource("jfxtest2/Screen.fxml"));
并且
Parent root = FXMLLoader.load(new URL("/jfxtest2/Screen.fxml"));
但它们都没有工作。那么我应该如何从 JFXTest2 类中的 JFXTest2 包加载 fxml,即
main
类(class)或 application class
.
最佳答案
尝试
Parent root = FXMLLoader.load(getClass().getResource("/jfxtest2/Screen.fxml"));
关于javafx - 如何从另一个包中找到 fxml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22918418/