使用fxml文件设置anchorPane的内容

sam*_*ara 4 javafx javafx-2 fxml

我使用手风琴控制.根据标题窗格,我需要将fxml文件加载到anchorPane中.所以我有两个部分:一个用于手风琴,另一个用于anchorPane,根据点击显示内容.

@FXML
private StackPane tmpPane;

@FXML
private void itemMembres(MouseEvent event) throws IOException { 
    tmpPane.getChildren().add((Node)FXMLLoader.load(getClass().getResource("/view/test.fxml")));
}
Run Code Online (Sandbox Code Playgroud)

tmpPane是视图中的anchorPane.

谢谢

sam*_*ara 9

我找到了解决方案

  • 通过扩展fxml文件来创建节点

  • 使用setAll AnchorPane

    @FXML
    private AnchorPane tmpPane
    
    @FXML
    private  void itemMembres(MouseEvent event) throws IOException{
    
    Node node;
    node = (Node)FXMLLoader.load(getClass().getResource("/view/MembresTableau.fxml"));
    tmpPane.getChildren().setAll(node);
    ...}
    
    Run Code Online (Sandbox Code Playgroud)