I would like to communicate with a FXML controller class at any time, to update information on the screen from the main application or other stages.
Is this possible? I havent found any way to do it.
Static functions could be a way, but they don't have access to the form's controls.
Any ideas?
Best Answer
You can get the controller from the
FXMLLoader
store it in your main stage and provide getFooController() getter method.
From other classes or stages, every time when you need to refresh the loaded "foo.fxml" page, ask it from its controller:
updatePage() can be something like:
in the FooController class.
This way other page users do not bother about page's internal structure like what and where
Label lblData
is.Also look the https://stackoverflow.com/a/10718683/682495. In JavaFX 2.2
FXMLLoader
is improved.