I want to create a Programm with FXML. I have multiple FXML-Documents with Controllers for each Documents. But the way I tried to do it does not work beause the Object of the Controller is null.
<HBox fx:id="A" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"
fx:controller="controllers.AController" alignment="BOTTOM_LEFT">
<Pane fx:id="B" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"
fx:controller="controllers.BController" HBox.hgrow="ALWAYS" maxWidth="Infinity"/>
2 of them have to know each other.
I imagine it to be like :
FXMLLoader Aloader = new FXMLLoader(getClass().getResource("/views/A.fxml"));
HBox toolbar = ALoader.load();
FXMLLoader Bloader = new FXMLLoader(getClass().getResource("/views/B.fxml"));
HBox toolbar2 = BLoader.load();
Then the AController should recieve the initialized Controller from B.
AContoller ac = Aloader.getController();
BCOntroller bc = Bloader.getController();
ac.setBController(bc);
there is a method in AController that looks like but "getController()" returns a completley new instance of the controller associated with the fxml :
public class AController{
private BContoller bc;
public void setBController(BController b){
bc = b;
}
};