如何从另一个包中找到fxml?

编程入门 行业动态 更新时间:2024-10-07 04:29:08
本文介绍了如何从另一个包中找到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?

本文发布于:2023-07-04 09:20:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1022299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:包中   fxml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!