# Confused about Components and setOpaque

**URL:** <https://forum.juce.com/t/confused-about-components-and-setopaque/12752>\
**Category:** General JUCE discussion\
**Created:** [April 25, 2014, 8:37am UTC](https://forum.juce.com/t/confused-about-components-and-setopaque/12752 "2014-04-25T08:37:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FullCode](https://avatars.discourse-cdn.com/v4/letter/f/41988e/32.png) [@FullCode](https://forum.juce.com/u/FullCode)\
**Post date:** [April 25, 2014, 8:37am UTC](https://forum.juce.com/t/confused-about-components-and-setopaque/12752/1 "2014-04-25T08:37:51Z")

</div>

I noticed that when I created a custom Component in my plug-in and call setOpauqe(true) that other components from the window draw inside the Components bounds.&nbsp;&nbsp;As a test&nbsp;I added a "do nothing" component to the Juce demo plug-in and it does the same thing. &nbsp;I would expect that it would only redraw the area that is directly underneath the Component.

I attached a pic so you can see what I mean. &nbsp;See how the text "Juce v3.0.4" duplicated in the other component. &nbsp;If I adjust other widgets then they will redraw in the same spot. &nbsp;Can anyone enlighten me how this is supposed to work? &nbsp;Why doesn't it just redraw the grey blank area that is underneath?

Thanks,

Chris

&nbsp;

![](http://www.juce.com/sites/default/files/forum/attachments/JuceComponent.png)

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [April 25, 2014, 9:17am UTC](https://forum.juce.com/t/confused-about-components-and-setopaque/12752/2 "2014-04-25T09:17:34Z")

</div>

setOpaque ist just the information for the juce renderer, that the component itself will repaint, its whole area, if it does not, &nbsp;the result will be unpredictable.

May it should be renamed, something like setHasOpaqueBehavior&nbsp;

&nbsp;

&nbsp;//==============================================================================  
&nbsp; &nbsp; /\*\* Indicates whether any parts of the component might be transparent.  
&nbsp; &nbsp; &nbsp; &nbsp; Components that always paint all of their contents with solid colour and  
&nbsp; &nbsp; &nbsp; &nbsp; thus completely cover any components behind them should use this method  
&nbsp; &nbsp; &nbsp; &nbsp; to tell the repaint system that they are opaque.  
&nbsp; &nbsp; &nbsp; &nbsp; This information is used to optimise drawing, because it means that  
&nbsp; &nbsp; &nbsp; &nbsp; objects underneath opaque windows don't need to be painted.  
&nbsp; &nbsp; &nbsp; &nbsp; By default, components are considered transparent, unless this is used to  
&nbsp; &nbsp; &nbsp; &nbsp; make it otherwise.  
&nbsp; &nbsp; &nbsp; &nbsp; @see isOpaque, getVisibleArea  
&nbsp; &nbsp; \*/  
&nbsp; &nbsp; void setOpaque (bool shouldBeOpaque);  
&nbsp;

---

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [April 25, 2014, 9:47am UTC](https://forum.juce.com/t/confused-about-components-and-setopaque/12752/3 "2014-04-25T09:47:00Z")

</div>

If you call SetOpaque(true) on a component, you are declaring that its paint() function will definitely render it opaque - i.e. no pixels within its bounds will have any transparency. You also need to make sure that this is indeed the case! The simplest way to ensure this&nbsp;is to start your paint() function with a 'g.fillAll()' using an opaque colour.

> Why doesn't it just redraw the grey blank area that is underneath?

It doesn't redraw the area behind it because&nbsp;you've explicitly told the renderer that it doesn't need to! Perhaps you have the meaning of the word 'opaque' inverted in your head! :) if you want the background to be drawn behind it, then you clearly want it to be transparent (which it is, by default), so&nbsp;don't call setOpaque(true).

&nbsp;

tldr;&nbsp;You should only set a component to be opaque if you know that you _won't_ be able to see what is behind it.

---

<div class="post-metadata">

**Author:** ![FullCode](https://avatars.discourse-cdn.com/v4/letter/f/41988e/32.png) [@FullCode](https://forum.juce.com/u/FullCode)\
**Post date:** [April 25, 2014, 10:16pm UTC](https://forum.juce.com/t/confused-about-components-and-setopaque/12752/4 "2014-04-25T22:16:00Z")

</div>

Thanks guys. &nbsp;I&nbsp;still don't understand why it draws&nbsp;a duplicate&nbsp;of the other redrawn&nbsp;components&nbsp;inside the component. &nbsp;For example, let's say I adjust the Throughput Level control it will draw copy of the control inside the other component rect. &nbsp;Of&nbsp;course the behvior is&nbsp;undefined so I guess I shouldn't expect otherwise...

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [April 25, 2014, 11:35pm UTC](https://forum.juce.com/t/confused-about-components-and-setopaque/12752/5 "2014-04-25T23:35:17Z")

</div>

It's just junk, probably the last clip rect to be drawn and as you've explicitly told the graphics context&nbsp;not to clear itself (by setting _setOpaque (true)_) it will just end up drawing whatever was last in the context.
