简体   繁体   中英

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. The FXML files are linked to controller classes.

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)

As fabian said, I would throw the controller into 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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