在javafx中加载多个fxml [英] Loading multiple fxml in javafx

查看:1178
本文介绍了在javafx中加载多个fxml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一段时间,但我无法得到我想做的事情。我一直在使用javafx框架在javafx中切换此线程中的fxml'正在加载同一场景中的新fxml '取得了一些成功。我的意思是,我有一个主窗口,这个窗口有两个不同的区域,MAIN区域和CONTENT区域。

I've been searching for a while and I haven't been able to get what I wanted to do. I've been using the javafx framework to switch fxml in javafx in this thread 'Loading new fxml in the same scene' with some success. I mean, I have a main window, and this window have two different areas, the MAIN area, and the CONTENT area.

MAIN区域在整个应用程序中保持不变,但CONTENT区域将不断变化。我的MAIN区域只有一个工具栏,根据您单击的工具栏中的哪个按钮,CONTENT区域中的fxml(和行为)将发生变化。

The MAIN area will remain the same in the whole application, but the CONTENT area, will be changing constantly. My MAIN area has just a toolbar, and depending which button in the toolbar you click, the fxml (and the behavior) in the CONTENT area will change.

我已经有了这种行为,它就像使用该框架的魅力一样。

I already have that behavior and it works like a charm using that said framework.

问题是,我希望我的所有内容区域也可以拥有自己的主要区域,以及自己的内容区域。并且取决于你在第二个MAIN区域中做了什么,fxml和第二个CONTENT区域中的行为也会发生变化。

The thing is, that I want that all my CONTENT areas could have their own MAIN areas too, and an own CONTENT areas too. And depending on what you do in that second MAIN areas, the fxml and the behavior in that second CONTENT areas changes too.

我不知道框架我是不是使用就足够了,如果我能够得到我想用它做的事情。

I don't know if the framework I'm using is enough and if I will be able to get what I want to do using it.

您是否知道另一个可以帮助我获得该功能的不同框架?

Do you know another different framework that could help me to get that functionality?

非常感谢提前!

推荐答案

您加载的每个 .fxml 都可以拥有自己的控制器。每个控制器都可以像主要控制器那样拥有自定义操作和加载代码。

Every .fxml that you load can have its own controller. Every controller can have custom action and loading code just like your main one does.

基本上,JavaFX是模块化的。如果主窗格中有可能出现问题,那么它的所有子窗口都可以实现。

Basically, JavaFX is modular. If something is possible in your main pane, then it's possible in all its children too.

通常,在基于UI的框架中,保持层次结构是明智的想法控制器,它们反映了各自组件的层次结构。如果你想获得子元素的子控制器(例如,为了将引用传递给父控制器),那么你就不能依赖 FXML.load()快捷方式,你必须使用更长的语法:

Generally, in UI-based frameworks, it is a wise idea to keep a hierarchy of controllers that mirrors the hierarchy of their respective components. If you want to get the child controller for the child element (for example, in order to pass the reference to the parent controller), then you can't rely on the FXML.load() shortcut, you have to use the longer syntax of:

FXMLLoader loader = new FXMLLoader(getClass().getResource("your.fxml"));
YourPaneType pane = loader.load();
YourControllerType controller = loader.getController();

这篇关于在javafx中加载多个fxml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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