Components Won't Draw In Resize, Only In Paint

I’ve been working on ironing out some of the bugs in the MyoMapper application ( and have noticed a problem in that the child components aren’t drawn and scaled in the resize function in the MainComponent class, and instead are set in the paint function.

Having trawled through the code, I cannot find out how to fix this as it is causing a few other problems with the code (namely using the toggleButtons for redrawing). Any ideas on why this is and any potential sollutions?

I think it’s a very common approach for GUI toolkits to do the resizing of the components and child components and accumulate a list of dirty regions along the way. After this the dirty regions are repainted. Anything else would be horribly inefficient.

But maybe I didn’t understand your question correctly?

Sorry, I’m still quite new to JUCE and had got it in my head that the source of my bug was the code was the resizing all being done in the paint method as I’d not seen it done like this before (I’d soley seen the bounds and size setting done in the resize function, but the MyoMapper code soley uses the paint function instead). I’ve a bug where the other panels in the plugin don’t appear until the mouse has moved off the ToggleButton after it has been clicked, what could be the cause of the problem if this is not it?

Yeah, that won’t really work.

Yep. The paint() method is probably the worst possible place to do resizing!

The resizing code was duplicated in both resized() and paint(). Removing the code in resized() [as shown below] allows the program to continue functioning how it currently does, however if I remove the code in paint() then the panels don’t ever get drawn after the ToggleButton’s are clicked.

Then presumably they need to be resized in response to something other than the parent’s size changing.

Doing this in paint() means that they’ll repeatedly be resized, but that doesn’t mean it’s the right place to do it. Pretty much anywhere else would be fine - do it on a timer, or in the constructor, on in visiblityChanged() or some other special callback that you call when something relevant happens. But for god’s sake, not in paint()!!

1 Like

I figured that paint wasn’t the right place to do it :slight_smile: Thanks again Jules!