BorderPane.getCenter() literally gets the node from the center region of BorderPane

521 Views Asked by At

I noticed that BorderPane.getCenter() removes the node that it returns from the region where it is placed. What I'm trying to do is to mirror the child inside the center of BorderPane and put it into another BorderPane to check if my code(attempt of memory releasing when if a tab is not selected by setting it to null) is working. Here is my code:

TabPane.getSelectionModel().selectedItemProperty().addListener((obs,ov,nv)-{

    //checks if "MyTab" tab is selected
    if (nv.getText().equals("MyTab")) {
        try {
                MyTabBP.setCenter(FXMLLoader.load(getClass().getResource("MyTab.fxml")));
                MirrorBP.setCenter(MyTabBP.getCenter());
            } catch (IOException ex) {
                Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

      //  else {
      //      MyTabBP.setCenter(null);
      //  }

    });

What I noticed (when I commented out the else block) is that after clicking MyTab, the BorderPane MyTabBP would be empty, and after checking MirrorBP(that is at another Tab), that is where the fxml that I loaded in MyTabBP was inserted into. After checking the BorderPane documentation, it said that

getCenter() Gets the value of the property center.

So I thought that it would just replicate everything that is inside the center of MyTabBP. So my question is how could I mirror the contents of a region(top, left, bottom, right, center) of a BorderPane? And hopefully that once a change happened at the node, it would update those who is referencing to it. So that I could test if this is actually working.

MyTabBP.setCenter(null);

Any help would be great. Thanks!

0

There are 0 best solutions below