Main window does not repaint when second window is displayed

i have a main window and i created another one . I display it when a certain button is pressed on the main window. It works but the problem is that it does not repaint the main window when the second one is being displayed. When i click on second one and try to move it - I think it calls resized() at that point- it starts painting the main window. I have some LED animations on main window. So it is really annoyying to see that main window stops painting . Why don’t they work at the same time ? Is there a parameter that i should set to make them work at the same time ?

i don’t know. But perhaps your LEDs should be separate child components, that also inherits a Timer at the rate you want them to display. The timer callback will should then call repaint(). Juce will then update them when it can.

1 Like

Yes, I created a LED component, that refresh 30 images in a time period according to value of a knob. I use a timer in that component.I only have a method that gets the knob value in it. Without second window everything works perfectly but when the second one is opened main window freezes. And it is not only the LEDs. Everything freezes including some other indification images.

I only open another window as a ‘DocumentWindow’ component for my user registration input. And everything works OK for that. Perhaps someone else will know what’s wrong, if you can post some code? Does it come back to life when it’s in keyboard focus?

1 Like

I tried to follow the steps in window demo.


#pragma once

 #include "../JuceLibraryCode/JuceHeader.h"
 #include "VersionWindowGui.h"
class VersionWindowShell    :public DocumentWindow
VersionWindowShell(const String& name, Colour backgroundColour, int buttonsNeeded);

void paint (Graphics&) override;
void resized() override;

void closeButtonPressed() override;

int creationCounter = 0;



#include "../JuceLibraryCode/JuceHeader.h"
#include "VersionWindowShell.h"

  VersionWindowShell::VersionWindowShell(const String& name, Colour backgroundColour, int buttonsNeeded):  DocumentWindow(name, backgroundColour, buttonsNeeded)
// In your constructor, you should add any child components, and
// initialise any special settings that your component needs.
setSize(400, 300);



  void VersionWindowShell::paint (Graphics& g)

      void VersionWindowShell::resized()
         // This method is where you should set the bounds of any child
        // components that your component contains..


  void VersionWindowShell::closeButtonPressed()
     delete this;



 #pragma once

    //[Headers]     -- You can add your own extra header files here --
   #include "../JuceLibraryCode/JuceHeader.h"


An auto-generated component, created by the Projucer.

Describe your class and how it works here!
    class VersionWindowGui  : public Component,
                      public HyperlinkButton::Listener
VersionWindowGui ();

//[UserMethods]     -- You can add your own custom methods in this section.

void paint (Graphics& g) override;
void resized() override;

/** Called when the button is clicked. */
void buttonClicked(Button*) override;
HyperlinkButton hyperlink;

       // HyperlinkButton hyperlinkbutton;
//[UserVariables]   -- You can add your own custom variables in this section.



   //[EndFile] You can add extra defines here...


   //[Headers] You can add your own extra header files here...

 #include "VersionWindowGui.h"

    //[MiscUserDefs] You can add your own user definitions and misc code here...

    VersionWindowGui::VersionWindowGui ()
//[Constructor_pre] You can add your own custom stuff here..



hyperlink.setURL({ "" });
setSize (400,300);

//[Constructor] You can add your own custom stuff here..

//[Destructor_pre]. You can add your own custom destruction code here..

//[Destructor]. You can add your own custom destruction code here..

void VersionWindowGui::paint (Graphics& g)
//[UserPrePaint] Add your own custom painting code here..

// g.fillAll (Colour (0xff323e44));

DBG("VersionWindowGui has been displayed!!!");

Font font("Cooper Std","Regular",16.0f);


g.drawFittedText("My plugin \n Version 1.0 ",getLocalBounds(), Justification::centred,2,1);
// hyperlink.getLookAndFeel().setColour(1,Colours::antiquewhite);

//[UserPaint] Add your own custom painting code here..


void VersionWindowGui::buttonClicked(Button*)


    void VersionWindowGui::resized()
//[UserPreResize] Add your own custom resize code here..
hyperlink.setBounds(0, 0, 150, 20);
Point<int> hyperCentrePoint(200, 250);
//[UserResized] Add your own custom resize handling here..


     //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...

  #if 0
  /*  -- Projucer information section --

This is where the Projucer stores the metadata that describe this GUI layout, so
make changes in here at your peril!


     <JUCER_COMPONENT documentType="Component" className="VersionWindowGui" componentName=""
             parentClasses="public Component" constructorParams="" variableInitialisers=""
             snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
             fixedSize="0" initialWidth="600" initialHeight="400">
     <BACKGROUND backgroundColour="ff323e44"/>

   //[EndFile] You can add extra defines here...

and in my main window buttonpressed method:

     if (versionWindowShell!=nullptr) { versionWindowShell->closeButtonPressed(); }

			 versionWindowShell = new VersionWindowShell("About", Colours::grey, DocumentWindow::allButtons);

				versionWindowShell->setContentOwned(new VersionWindowGui(), true);

				//Rectangle<int> area(0, 0, Component::getParentWidth() / 2, Component::getParentHeight() / 2); 
				Rectangle<int> area(0, 0, 400, 300); 

				RectanglePlacement placement(RectanglePlacement::xMid
					| RectanglePlacement::yMid
					| RectanglePlacement::doNotResize);

				//auto result = placement.appliedTo(area,Component::getParentComponent()->getBounds());

				auto result = placement.appliedTo(area, Desktop::getInstance().getDisplays().getMainDisplay().userArea);
				versionWindowShell->setBounds(result); // this works . it is for arranging the screen according to display sizes




The only differences I can see is that I use a static function to create my window:

Component *makeRegWindowContent(Registration &reg) { return new RegWindowContentComponent(reg); }

Which I call in my DocumentWindow constructor:

	setContentOwned(makeRegWindowContent(reg), true);
	centreWithSize(getWidth(), getHeight());
1 Like

Then I will try to do the same :slight_smile: maybe it is because of that. Thank you

Have you looked at the ‘WindowsDemo’ in the examples?

yes, that’s how i did mine actually :confused:

And that works OK for you once the dialogue box is quit?

Everything works but when i create the window, it pops up on my main window perfectly. You can test my code. But when it is displayed the main window stops repainting in the background. When i click on the window and try to move it by dragging it to left,right, up or down, the main window starts calling paint method again. So it starts performing my LED animation.

Problem solved. It was because of this line

1 Like