JavaFX how to close an internal AnchorPane

1
Hello everyone, my question is I have an AnchorPane child that is added inside the AnchorPane parent in my AnchorPane child. I have a button called CloseAnchorPane my problem.

How do I close the AnchorPane child without closing the parent AnchorPane?

My code looks like this:

@FXML
private Button btnFacharAnchorPane;

@FXML
public void fachar() {
    btnFecharAnchorPane.getScene().getWindow().hide();
}

When I click the button it close the whole program, what I want is that it closes only the inner AnchorPane which is the child

    
asked by anonymous 22.08.2017 / 17:46

2 answers

1

You can use the setVisible() method to hide and show AnchorPane , in the action of the fecharPane() button, you should only add the following

        @FXML
        public void fecharPane(ActionEvent evt){
          filho.setVisible(false);
        }
    
22.08.2017 / 22:29
0

To do this you must assign an ID to the parent AnchorPane and modify its method according to the code below:

@FXML
private AnchorPane pai;

// [...]

@FXML
public void fecharPane(ActionEvent event){
    // Remove do array de filhos o pane que contém o botão
    pai.getChildren().remove(mybutton.getParent());
}

Result: (AnchorPane parent in blue and child in red)

    
22.08.2017 / 19:30