How to change sub fxml gui parts at runtime with Button Click

前端 未结 2 1645
你的背包
你的背包 2021-02-01 06:23

I\'m tryin to build a skeleton for a big complex gui, so the idea is to make everything with mvc like style in javafx 2.1, so every component has a fxml file and if needed css,c

相关标签:
2条回答
  • 2021-02-01 06:54

    Don't just include fxml, create a business logic layer for that:

    <BorderPane xmlns:fx="http://javafx.com/fxml">
    <center>
        <Pane fx:id="content"/>
    </center>
    

    and update it in button click handlers:

    @FXML
    private void handleTaskBarButton2Action(ActionEvent event) {
       System.out.println("click! taskBarButton2");
       content.getChildren().clear();
       content.getChildren().add(FXMLLoader.load(getClass().getResource("Content2.fxml"));
    }
    
    0 讨论(0)
  • 2021-02-01 06:57

    it works,thx for help, but i was forced to remove TaskBar.fxml and TaskBarController.java , wrote a MainViewController with @FXML handles and @FXML for the Buttons and the Pane with the fx:id="content" , and put my customs Buttons in MainView.fxml

    @FXML
    private void handleTaskBarButton2Action(ActionEvent event) throws IOException {
        System.out.println("click! taskBarButton2");
        content.getChildren().clear();
        content.getChildren().add((Node) FXMLLoader.load(getClass().getResource("Content2.fxml")));
    }
    
    0 讨论(0)
提交回复
热议问题