Paint Performance when Multiple Components have the same Bounds



Does it impact paint performance if multiple components share the same position and size and all of them are setVisible(true) but of course only the topmost is seen on screen. Will JUCE only renderer the topmost component and not draw any other components at the same position and size that are placed behind it? or will the other components be rendered too but they are just not visible? so it would impact performance?

what i’m trying to do is fading between components.
lets say i got at least 2 components (componentA, componentB) both placed at 0,0,500,500. both visible but only the topmost component is seen.
now i got 2 buttons to switch which one should be visible on front.
i do the following if button A is clicked…

Desktop::getInstance().getAnimator().fadeIn(componentA.get(), 200);

and when i click on button B…

Desktop::getInstance().getAnimator().fadeIn(componentB.get(), 200);

The transition works fine and looks great! But if the components that are not seen are rendered too i have to change my code because i don’t want to waste performance…

Thanks in advance!


add some DBG() statements to each component’s paint() method and check the console output.


If a component has an alpha of 0 or you’ve called setVisible (false) on it then it won’t be drawn. But otherwise yes, all the bits of components that are in the repaint area and which aren’t behind an opaque component will need to be drawn each time.


Also please check “Component::setBufferedToImage” - maybe it helps. It “makes the component use an internal buffer to optimise its redrawing.”


Thanks a lot for all the replies. i already changed the code…
when clicked on button A i do…

Desktop::getInstance().getAnimator().cancelAnimation(componentA.get(), false);
Desktop::getInstance().getAnimator().fadeOut(componentB.get(), 200);

i still got the same fade effect but only one component is visible now…

thanks again