如何从另一个包中找到fxml? [英] how to locate fxml from another package?

查看:186
本文介绍了如何从另一个包中找到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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆