0
votes

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)

1
Nope, unless you store the controller e.g. in the userData property when loading which would allow you to store this data in a more convenient data structure. - fabian

1 Answers

2
votes

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.