You cannot install more than one controller in an FXML file using (fx:controller="") , instead consider entering a controller manually, there are basically two ways:
Using the setController method without mentioning the controller inside the FXML file:
FXMLLoader loader = new FXMLLoader(); URL location = getClass().getClassLoader().getResource("fxml/ClientArea.fxml"); loader.setLocation(location); loader.setController(new ClientArea()); // loader.setController(new Undecorator()); loader.load();
In a more appropriate way, use the setControllerFactory method:
first make sure that both ClientArea and Undecorator implement the interface ( Icontroller containing event handler methods) specified in the FXML file (fx:controller="IController") , then select the controller when loading your view from the FXML file:
FXMLLoader loader= new FXMLLoader(); URL location = getClass().getClassLoader().getResource("fxml/ClientArea.fxml"); loader.setLocation(location); loader.setControllerFactory(new Callback<Class<?>, Object>() { public Object call(Class<?> p) { return new ClientArea();
source share