1

メニューをクリックしたときにボーダーペインの中心を変更したいのですが、「ルート値は既に指定されています。」というエラーが表示されます。まず、以下のように初期化します

@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);
    }

初回の読み込みはうまくいきますが、他の fxml ファイルを再読み込みしようとすると、エラーが表示されます。

@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 {
        }

    }

そして私のfxmlファイルはこのようなものです..

 <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>

borderpane を含む fxml は次のようになります。

<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>

これは、メニューをクリックしたときに変更したいものです

<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">

誰かが私にこの問題を助けてくれますか?

4

0 に答える 0