Clear components within a Tab

0

I have a method that cleans my components, however, it can not clean components that are within Tab .

I was trying to apply it as follows:

if (fieldValue instanceof Tab) {
    for (Tab tab : ((Tab) fieldValue).getTabPane().getTabs()) {
        if (tab instanceof Tab) {
            // ((Tab) fieldValue).getTabPane().getContentBias().getChildrenUnmodifiable().clear();
            ((Tab) fieldValue).getTabPane().getTabs().clear();
         }
     }

What happens is that I have not been able to get these components, and in my attempt, it ends up removing all tabs. Does anyone have any suggestions, some way to give getComponenets() or something like this?

Detail, that fieldValue has all components instantiated and Tab type.

    
asked by anonymous 27.07.2017 / 19:19

1 answer

1

In this case you have to clean the Container that is attached to the Tab (Usually an AnchorPane for SceneBuilder users).

Recovering components: To recover the nodes that exist inside a Container, use the getChildren () , which will return an ObservableList of nodes (nodes = components).

Retrieving the tab container: If you do not want to assign ID's to every Pane you can use the getContent () of your Tab to retrieve the container.

If you wanted to clean all nodes use container.getChildren().clear() , if it's just a specific component use getChildren().remove(Object o) and its variants.

[EDIT - was giving an error because getContent returns a Node and the getChildren method is of Pane class]

In your case, I think it looks like this:

if (tab instanceof Tab){
    // Modo 1: Todas as tabs tem um AnchorPane como container
    // AnchorPane pane = (AnchorPane) tab.getContent();

    // Modo 2: Tabs tem Containers diferentes
    Pane pane = (Pane) tab.getContent();
    pane.getChildren().clear();

    // Modo 3: Forma curta do modo 2
    // ((Pane) tab.getContent()).getChildren().clear();
}

I tested it this time and I succeeded. Hope it helps.

Note: In your loop the .getTabs () method is executed at each iteration, would not it be better to store this in an ObservableList?

    
27.07.2017 / 19:57