intellij-idea - jar中的Javafx无法打开新场景
问题描述
在我的主控制器应用程序中,我尝试打开新场景
public void runReportParserWindow() throws IOException {
System.out.println("Open report parser window");
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("../views/reportWindow.fxml"));
ControllerReportParser controller = new ControllerReportParser(getPrimaryStage(), getMainApp());
controller.registerObserver(this);
fxmlLoader.setController(controller);
Scene scene = new Scene(fxmlLoader.load());
Stage stage = new Stage();
stage.setTitle("Get data for report");
stage.setScene(scene); //scene
stage.initModality(Modality.WINDOW_MODAL);
stage.initOwner(getPrimaryStage());
stage.show();
}
如果我在 Intellij idea 中运行应用程序 - 所有窗口都可以正常打开。当我创建 JAR 文件(工件)时,我无法打开除主窗口之外的任何窗口。显示了主要场景,但没有显示其他场景。工件的设置
我究竟做错了什么?
解决方案
非常感谢 James_D 我使用相对路径来加载 fxml 文件。现在我将视图文件夹替换为控制器并更改代码
fxmlLoader.setLocation(getClass().getResource("../views/reportWindow.fxml"));
到
fxmlLoader.setLocation(getClass().getResource("views/reportWindow.fxml"));
一切正常。
推荐阅读
- angular - 在不在组件中的类中调用服务
- node.js - 使用axios调用api时无法从api下载文件响应
- html - 我在 .html 或 .css 中的白色部分有问题 我不知道我是编码新手
- javascript - Javascript if 语句即使在 false 时也会执行
- ruby - 如何在ruby中更改类中的实例变量
- go - 取消上下文取消的进一步操作
- ionic-cli - npm 错误!ERESOLVE 无法解析依赖树
- flutter - 如何在 ListView 中显示 FontAwesome 库中的所有图标?
- c++ - 如何通过 IMFSourceReader 使用自定义堆
- linux - 木偶,希拉 | 如何获得价值