Tuesday, 13 August 2013

How to build a Control from FXML markup?

How to build a Control from FXML markup?

Classes
MainGUIController.java
main_gui.fxml
login_gui.fxml
What I want to do
The main_gui.fxml has a tag containing an empty AnchorPane, just like this:
<AnchorPane fx:id="login" />
In the MainGUIController.javaclass, I want to inject the login_gui.fxml
markup into the AnchorPane object. I want to do this because the Login
Screen will be in the Main Screen, but I want a separated controller just
for the login_gui.fxml.
I tried using the FXMLLoaderclass like this:
Declaration
@FXML
private Pane login;
Code
LoginGUIController controller = new LoginGUIController();
FXMLLoader loader = new FXMLLoader();
loader.setController(controller);
loader.setLocation(getClass().getResource("login_gui.fxml"));
login = (Pane) loader.load();
The app loads, but nothing appears. No exception is thrown. Is there a way
to do what I want to?

No comments:

Post a Comment