Access the contents of a TitledPane in JavaFX

1

I want to access all the nodes that are contained in a TitledPane for which I loop:

for ( Node panel :  panelTitulado.getChildren()){                  
             System.out.println ("Nodo: " + panel.toString());                      
         } 

This procedure works for containers like VBox but not for TitledPane since there is no property getChildren() Is there any property that allows access to the content to know all the nodes there in?

    
asked by Oundroni 24.03.2016 в 16:32
source

2 answers

1

You must use getContent() , for example:

for ( Node panel :  panelTitulado.getContent()){                  
             System.out.println ("Nodo: " + panel.toString());                      
    } 

It is important to cast the type of container that is regularly AnchorPane :

for ( Node panel:  ((AnchorPane) panelTitulado.getContent()).getChildren()){
            System.out.println ("Nodo: " + panel.toString());
            System.out.println ("Nodo Id : " + panel.getId().toString());
        }

This way you can get the information of the nodes contained within TitledPane

Nodo: Main$3[id=id1]
Nodo id: id1
Nodo: Main$4[id=id2]
Nodo id: id2
Nodo: Main$5[id=id3]
Nodo id: id3
Nodo: Main$6[id=id4]
Nodo id: id4
    
answered by 24.03.2016 / 17:25
source
0

If you want to access all the nodes of a TitledPane , you must first obtain the content of this, then make a casting of Node obtained to the specific type of layout established and on this invoke getChildren .

Suppose we have created the content of our TitlePane like this:

TitledPane panelTitulado = new TitledPane();

AnchorPane miLayout = new AnchorPane();
miLayout.getChildren().add(miNodo1);
miLayout.getChildren().add(miNodo2);
myLayout.getChildren().add(miNodon);

panelTitulado.setContent(myLayout);

Now, the reverse process would be:

AnchorPane myLayout = (AnchorPane) panelTitulado.getContent();
myLayout.getChildren().forEach((Node panel) -> {
    System.out.println ("Nodo: " + panel.toString());
});

Keep in mind that to get myLayout nodes I use the method forEach together with an lambda expression enabled from version 8 of java.

    
answered by 24.03.2016 в 18:13