简体   繁体   English

通过来自其他类的Scene对象访问JavaFX的控制器类(对象)

[英]Accessing Controller Class (Object) of JavaFX by Scene object from other classes

I am loading scenes from FXML and store the scenes in a Deque for changing menus. 我正在从FXML加载场景,并将场景存储在Deque中以更改菜单。 The FXML files are linked to controller classes. FXML文件链接到控制器类。

I want to know is there any way to access controller class (Actually controller instance) of scene from scene? 我想知道有什么方法可以从场景访问场景的控制器类(实际上是控制器实例)吗?

For example is there any way to do something like this: 例如,有什么方法可以执行以下操作:

Scene scene = scenes.getLast();
scene.getController(); //There is no such method by default

( scenes is a Deque that stores Scene Objects) scenes是存储场景对象的双端Deque

As fabian said, I would throw the controller into Scene#userData . 正如fabian所说,我会将控制器放入Scene#userData

In fact I use the userData property quite a bit for managing my views, stages, etc. -- mostly as an "id" of sorts for accessing them. 实际上,我大量使用userData属性来管理我的视图,阶段等-主要是作为访问它们的种类的“ id”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM