Maven项目中具有JavaFX依赖关系的.fxml文件在哪里? [英] Where are .fxml files in Maven project with JavaFX dependency?

查看:108
本文介绍了Maven项目中具有JavaFX依赖关系的.fxml文件在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Maven和JavaFX还是很陌生,所以我假设有一个简单的答案,但我一直找不到.

I'm pretty new to Maven and JavaFX so I'm assuming there's an easy answer, but I haven't been able to find it.

我想为我的项目创建一个GUI,这是我作为IntelliJ中的Maven项目拥有的.通过添加javafx-fxmljavafx-controls,我能够使GUI正常运行.当想尝试SceneBuilder时,我意识到找不到.fxml文件.

I want to create a GUI for my project, which I have as a maven project in IntelliJ. I was able to get a GUI to function as intended by adding javafx-fxml and javafx-controls. When wanting to try SceneBuilder I realized that the .fxml file was nowhere to be found.

一些消息来源说要在resources文件夹中查找,但似乎是空的.另一个人说还有第二个src文件夹(?),但是如果是这种情况,我找不到它.

Some sources say to look in the resources folder but that appears to be empty. Another says there is a second src folder(?) but if that's the case I can't find it.

推荐答案

假设您的软件包名称为com.example

Assume your package name is com.example

然后您的应用程序代码在这里<project root>\src\main\java\com\example\App.java

Then your Application code is here <project root>\src\main\java\com\example\App.java

将您的FXML放在这里<project root>\src\main\resources\com\example\App.fxml

Place your FXML here <project root>\src\main\resources\com\example\App.fxml

使用Java代码加载FXML

Load your FXML using Java code

Parent root = FXMLLoader.load(getClass().getResource("App.fxml"));
Scene scene = new Scene(root);

App.javaApp.fxml在同一个程序包中,因此getClass().getResource("App.fxml")可以正常工作

App.java as well as App.fxml are in the same package, therefore getClass().getResource("App.fxml") works fine

这篇关于Maven项目中具有JavaFX依赖关系的.fxml文件在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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