I'm having trouble when trying to switch from a scene to another scene. The scenario is this:
Current View and Controller: login.fxml
and LoginController
Next step View and Controller: loggedWindow.fxml
and UserPanelController
.
Now, I'm in LoginController
and trying to switch the scene to loggedWindow.fxml
sending to UserPanelController
a parameter, but when I'm using my code I get:
javafx.scene.layout.Pane cannot be cast to javafx.fxml.FXMLLoader
LoginController:
FXMLLoader loggedWindow = null;
loggedWindow = FXMLLoader.load(getClass().getResource("loggedWindow.fxml")); // here crashes!
Pane root = loggedWindow.load();
UserPanelController controller = loggedWindow.getController();
controller.initData(customer);
Stage switchScene = (Stage)((Node)event.getSource()).getScene().getWindow();
switchScene.setResizable(false);
switchScene.setTitle("Welcome " + customer.FirstName + " " + customer.LastName);
switchScene.setScene(new Scene(root, 800, 500));
switchScene.show();
LoggedWindow.fxml
<Pane maxHeight="500.0" maxWidth="800.0" minHeight="500.0" minWidth="800.0" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Main.UserPanelController">
<children>
<ToolBar prefHeight="40.0" prefWidth="831.0">
<items>
.
.
stuff (buttons/labels and so on).
.
.
</Pane>
I would appreciate any help! Thanks in advance.
Update 1
Also took in consideration this reference: Accessing FXML controller class