JavaFX:已指定根值

时间:2015-11-22 08:19:39

标签: javafx fxmlloader

我想在单击菜单时更改borderpane的中心,但会弹出错误" Root value已经指定。"。 首先,我将其初始化为如下所示

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

有人会帮我解决这个问题吗?

0 个答案:

没有答案