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>

包含边框的 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