Parents and Childrens



I am stuck for long time already trying to solve a basic situation for experienced developers of JUCE but for me until now, impossible to solve.

I am making a application that as a MainWindow and that will open chidren components that will take the whole application desktop.

On this Children components I will open another children or have to come back to prior component.

On this process I am doing this way.

On main i declare setContentOwned (new MainContentComponent(), true) and also mainWindow = new MainWindow().

On component MainWindow i do a addAndMakeVisible(ChildComponent()).


How can i use a button to close my ChildComponent() and get back to my component MainWindow ?


Thanks for all your time,


I'm not quite sure what you are trying to do but if you want to hide a child component you can use Component::setVisible(false).

Hi Rory,

Basicly what i want to do is:

Have a MainWindow with some buttons.

Each of this buttons will open a new Component that will take the full application screen, in a way that the MainWindow will not be visible.

On this new Components I must be able to return to MainWindow pressing a button.

This new Components will also open another Components.

So basicly I have a parent that is the MainWindow and several childs of this parent. And this Childs will also have childs.

I need to be able to return to the main parent and also to be able to return to previous parent.

If I use Component::setVisible(false) will hide the component I am using, not destroying it ?

And if I want to come to MainWindow from the child of a Child, how can i do it ?


Thanks for your time,


That's correct. It will not destroy it. It just hides it from view. You can also call bringToFront() or sendToBack() at any stage on the components. They might be useful to you too. You can find the top level component using Component::getTopLevelComponent( ) and there are a few more utility methods for finding parent components that might help too. That's how you might do it, but I can't say if this is the best way to do what you want. It could be that using dialog windows might be better than trying to work it out with screen-sized components, and it could be easier to manage in the long run. If I'm not mistaken you can hide the dialog windows from the task bar so it doesn't look like your app has a load of windows open at the same time. I'm sure others can provide better advise on how best to go about the task, but it's certainly doable.