[G4P] How to iterate through Gpanel children ( Gpanel added controls)

Greetings

I am in the need of iterating through all children of a Gpanel. The thing is that I need to check if certain children inside of it does already exists so as not to add it again. Is it possible to implement? I haven't found anything regarding children iteration in the Gpanel docs.

Regards

Answers

  • Answer ✓

    G4P does not allow you to iterate through the children of a GPanel (or any other window or control).

    Since your program is responsible for adding controls to a GPanel it is simple enough to remember these controls in a separate list.

    ArrayList<GAbstractControl> controlsOnPanel = new ArrayList<GAbstractControl>();

    If you have a GPanel called panel and you add a control called control to the panel you also add it to the list like this

    panel.add(control);
    controlsOnPanel.add(control);
    

    So to find out if a control is on the panel then you just have to see if it's in the list controlsOnPanel

    GAbstractControl is the base class for all G4P controls so you can add sliders, buttons, textfields etc

  • edited March 2018

    Thanks quark. I was considering this approach too, in case of not having a method to get the panel's children. I will do it with a list :)

Sign In or Register to comment.