Clean components within a tab

Asked

Viewed 152 times

0

I have a method that cleans my components, however, it cannot clean the components that are inside a Tab.

I was trying to apply it this way:

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 can’t get hold of these components, and in my attempt, she ends up removing all the flaps. Does anyone have any suggestions, any way to give a getComponenets() or something like ?

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

1 answer

1

In this case you have to clean the Container that is attached to the Tab (Usually it is an Anchorpane, for Scenebuilder users).

Recovering the components: To recover the nodes that exist inside a Container the method is used getChildren(), which will return an Observablelist of nodes (nodes = components).

Recovering the container from the tab: If you don’t want to assign ID’s to each Pane you can use the method getContent() of his Tab to retrieve the container.

In case you wanted to clean all the nodes use container.getChildren().clear(), if it is only a specific component use getChildren().remove(Object o) and its variants.

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

In your case I believe it stays that way:

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 succeeded. I hope it helps.

Note: In your loop for the . getTabs() method runs every iteration, it would not be better to store it in an Observablelist ??

  • in getChildren() it says "cannot resolve method getChildren()"

  • 1

    I’ve never done it this way, really can’t access getChildren() directly from getContent(). I’m correcting my answer.

  • I added one more way of resolution and some considerations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.