Why isnt setBackgroundColor working here?

To start off, Im completely new to JUCE and am getting very frustrated by something as simple as changing the background color. I’ve opened up the basic GUI project and have used setBackgroundColour(juce::Colours::black); under MainWindow’s public, but it changes nothing and I’m confused why :confused:

Any help would be greatly appreciated. I really dont know what Im missing here.

Most likely a child component paints over the ResizableWindow you are setting the colour on. Or you did override the paint method of the ResizableWindow, as stated in the docs:

As a convenience the window will fill itself with this colour, but you can override the paint() method if you need more customised behaviour.

1 Like

Ah thank you for your response! I was looking in the mainComponent.cpp file, and this was what was causing the issue:

MainComponent.cpp file — g.fillAll (getLookAndFeel().findColour (juce::ResizableWindow::backgroundColourId));

Once I removed that, I was able to change the color in the main.cpp

I’m still really fresh on C++ and while I dont understand how I would change the above code to change the background there, I have been able to change the color in the main.cpp

Appreciate your help!

You could simply put your code into the MainComponent.cpp Paint function, except use the fillAll method instead of SetBackgroundColour.


The juce components delegate their drawing into the LookAndFeel class. The interface for each component is in a nested class called FooComponent::LookAndFeelMethods, which you will find in the docs.
This LookAndFeel is stateless, because it applies to all instances of that component. This means, in order to change the colours there needs to be a different mechanism.
Every component has a map, which maps an identifier from the FooComponent::ColourIds enum to a colour. If no mapping was set, it will try the LookAndFeel to find the colour for all FooCOmponents.

You can hardcode the colour by overriding the paint() calls, but that will stop the setColour from working. Once understood, the LookAndFeel delegation pattern and the colour lookup are a powerful tool to keep the look organised and not having to create new classes just to change a colour.