How could it know if a component is opaque or not? Keep in mind it has to draw the most background images first so it has to know this information about a component before it has started drawing the component. When you call setOpaque (true)
you’re essentially saying I promise not to make any part of my component transparent at all!
Daniel has basically already said it, but basically if a child component has to redraw then it has to transverse up the parents to cause them to redraw, even if the parent has setBufferedToImage (true)
called on it the image will be invalidated forcing a full redraw. If on the other hand the drawing is done in a sibling then the same is not true! (see here for more detail CachedComponentImage invalidation logic)
This is one of those gotchas that is really hard to realise what is going wrong so my recommendation is to never draw in a component that itself contains child components, basically separate container components and drawing components, and have drawing components only ever be the end node. There will of course be exceptions to the rule but it’s served me pretty well! I even brought this up during the Optimising graphics performance workshop at ADC with Jules and Tom, in an example they showed of setBufferedToImage
they had indeed made the background draw in a child component and it turned out that while writing the example Tom had been caught out by this when he originally made the component draw the background - which goes to show how easy it is to get caught out by this!