Repaint() function doesn't run paint(Graphics& g)

Hi all,
I have a screen, I draw something in

void paint(Graphics& g) override 
   // Paint something here

function. I want is every time the size of the screen is changed, the screen will be pain a gain. So, I called repaint(); in the function resized() like this:

void resized() override
   // Do something

But the paint(Graphics& g) wasn’t called after the resized() has been called? Can you help me solve this problem?

The components should be repainting themselves automatically when they are resized. Why are you trying to manually call repaint() from resized()?

Thank you @Xenakios
I want to draw some text like this “This is the link to th…” but when I zoom in my screen, the text isn’t changed. My expected result is the text should be “This is the link to the audio website” but it’s not.
My code in paint() here:

void paint(Graphics& g)



       g.drawFittedText(m_content, 0, 0, m_height, getLocalBounds().getWidth());

A repaint is triggered when a Component’s bounds are changed… not the size of the display. How are you zooming?

You can see how this all works by looking at the JUCE source code.


Have you ensured resized() itself is even called when zooming in the screen? Maybe there’s some other Component callback for that? Is this about a touchscreen device?

virtual void Component::mouseMagnify

Seems like a candidate…“Called when a pinch-to-zoom mouse-gesture is used”

I’m sure resized(); is called, I put a breakpoint inside the resized() to debug it

Component::resized() doesn’t trigger a repaint (check the source).

void Component::resized()                       {}
void Component::moved()                         {}
void Component::childBoundsChanged (Component*) {}
void Component::parentSizeChanged()             {}

Look at:




and search for when those are called in the JUCE code.


The poster’s problem appears to be that even if repaint() is called in his overridden resized() method, the repaint is apparently not being done. IMHO the repaint() call is not even necessary though, when the component has been resized, repaint() likely has been called by JUCE already. I wonder if the poster’s resized() implementation’s “do something” part is doing something relevant to the problem? :slight_smile:

Yes, there’s no point calling repaint() inside resized(), it’s already been done.

In my experience, if you’re calling repaint and the component isn’t repainting, then you’re probably calling it on the wrong component.

Like others pointed out: don’t put a repaint() in resized(). It will happen automatically, when the bounds are changed.
If you call repaint() on your Component, but no paint() is happening, there could be one of these situations:

  • the component is not visible at all (size > 0 and setVisible (true) or addAndMakeVisible not called)
  • the Component is hidden behind another Component, that is marked opaque but is not painting itself
  • what Jules just mentioned: confusion with the instances

or some more…

Good luck

1 Like

Thank all of you so much for your help. I tested and removed repain() from resized(). I’ll debug again to find out my problem here. :slight_smile: