How to load fxml file inside Pane?

Hussein Saied picture Hussein Saied · Nov 17, 2015 · Viewed 21.8k times · Source

enter image description here

If we have a Stage then Scene includes 2 Panes the 1st Pane contains Button and the 2nd Pane is empty could we load other fxml file inside this 2nd Pane?

fxml1: VBox
               |_Pane1-->Button
               |_Pane2
///////////////
fxml2: Pane--> Welcome to fxml 2
"when we click the button load the fxml2 inside Pane2 of fxml1"

Then after click

enter image description here


====I finally found this works after trying !====Thank you guys

@FXML Pane secPane;
public void loadFxml (ActionEvent event) {
Pane newLoadedPane =        FXMLLoader.load(getClass().getResource("/application/fxml2.fxml"));
secPane.getChildren().add(newLoadedPane); 
}  

Answer

Hussein Saied picture Hussein Saied · Nov 17, 2015

I finally found this works after trying !

@FXML Pane secPane;
public void loadFxml (ActionEvent event)  {
  Pane newLoadedPane =  FXMLLoader.load(getClass().getResource("/application/fxml2.fxml"));
  secPane.getChildren().add(newLoadedPane);
}