I want to change the center of borderpane when I click a menu but it pops up an error "Root value already specified.". At first, I initialize it like below
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
currentMenuNum = 0;
currentMenu = menuList[currentMenuNum];
currentViewerPath = "/managerworld/viewer/StartViewer.fxml";
System.out.println(currentMenu);
setControlItems(currentViewerPath,currentMenu);
}
private void setControlItems (String path, String currentMenu) {
//Display setting for menu
try {
fxmlLoader.setLocation(getClass().getResource(path));
anchorPane = fxmlLoader.load();
// fxmlLoader.load();
connectionViewerController = (ConnectionViewerController) fxmlLoader.getController();
} catch (Exception e) {
System.out.println(e.getStackTrace().toString());
System.out.println(e.getMessage());
}
borderPane.setCenter(anchorPane);
//controller setting
if (currentMenu.equals(currentMenu)) connectionViewerController = (ConnectionViewerController) fxmlLoader.getController();
else return;
//button setting
button2.setDisable(false);
button3.setDisable(false);
button4.setDisable(false);
button5.setDisable(false);
}
first time load is working well, but if I try to reload other fxml file, the error pops up.
@FXML
private void handleSelectMenus(MouseEvent event) {
if (event.getSource().equals(menuVBox1)) {
currentViewerPath = "/managerworld/viewer/ConnectionViewer.fxml";
currentMenuNum = 1;
currentMenu = menuList[currentMenuNum];
setControlItems(currentViewerPath,currentMenu);
} else {
}
}
and my fxml files are like this..
<AnchorPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<children>
<VBox alignment="CENTER" prefHeight="653.0" prefWidth="792.0" style="-fx-border-color: #D3D3D3;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Text fill="#656565" strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome to Manager World!">
<font>
<Font size="36.0" />
</font>
</Text>
<Text fill="#003975" layoutX="41.0" layoutY="329.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Click the Connection Menu to get started.">
<font>
<Font size="16.0" />
</font>
</Text>
</children>
</VBox>
</children>
</AnchorPane>
fxml which is including borderpane is like this..
<BorderPane fx:id="borderPane" maxHeight="768.0" maxWidth="1024.0" minHeight="768.0" minWidth="1024.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="managerworld.controller.ManagerWorldController">
<center>
</center>
and this is what I want to change if I click a menu
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="managerworld.controller.ConnectionViewerController">
<children>
<VBox spacing="5.0" style="-fx-border-color: #D3D3D3;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<GridPane alignment="CENTER_LEFT" layoutX="100.0" layoutY="100.0" BorderPane.alignment="CENTER">
Would someone help me this problem?