# Switching between independent components in JUCE

**URL:** <https://forum.juce.com/t/switching-between-independent-components-in-juce/21844>\
**Category:** Development\
**Created:** [April 15, 2017, 11:17pm UTC](https://forum.juce.com/t/switching-between-independent-components-in-juce/21844 "2017-04-15T23:17:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benchen](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@benchen](https://forum.juce.com/u/benchen)\
**Post date:** [April 15, 2017, 11:17pm UTC](https://forum.juce.com/t/switching-between-independent-components-in-juce/21844/1 "2017-04-15T23:17:41Z")

</div>

I want to create a button that can switch between two independent components. I can use  
`this->setVisible(false);` to remove my current GUI component but I am unable to put a different component in its place. Even though I create a new object called `mainContentComponent` and try the following `mainContentComponent->setVisible(true);` Does anyone have any suggestions on switching independent components that are located in different cpp files? All help is appreciated!

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [April 15, 2017, 11:35pm UTC](https://forum.juce.com/t/switching-between-independent-components-in-juce/21844/2 "2017-04-15T23:35:41Z")

</div>

Should actually work like that. Did you call addAndMakeVisible on the new one as well?  
And did you set the bounds in the resize method for the new one?  
If it was created after setSize, it might not have received a valid size…  
Good luck
