本文介绍了如何从另一个包中找到fxml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个简单的 JavaFX 应用程序。
I have created a simple JavaFX application.
它有两个包,主类是 JFXTest2。 java 位于 good 包中,fxml及其控制器位于 JFXTest2 包中。
It has two packages the main class is JFXTest2.java is in good package and the fxml and it's controller are in JFXTest2 package.
现在的问题是我无法在主类中加载fxml。我尝试像这样加载 fxml:
now the problem is that i can not load the fxml in the main class. I tried loading the fxml like this:
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这是主类或应用程序类。
but none of them worked.So how should i load the fxml from JFXTest2 package in the the JFXTest2 class which is the main class or application class.
推荐答案尝试
Parent root = FXMLLoader.load(getClass().getResource("/jfxtest2/Screen.fxml"));更多推荐
如何从另一个包中找到fxml?
发布评论