# Strange flickering

**URL:** <https://forum.juce.com/t/strange-flickering/9756>\
**Category:** General JUCE discussion\
**Created:** [January 2, 2013, 6:13pm UTC](https://forum.juce.com/t/strange-flickering/9756 "2013-01-02T18:13:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![younameit](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/younameit/32/14165_2.png) [@younameit](https://forum.juce.com/u/younameit)\
**Post date:** [January 2, 2013, 6:13pm UTC](https://forum.juce.com/t/strange-flickering/9756/1 "2013-01-02T18:13:16Z")

</div>

I’m designing a dynamic panel inside a tab and I have some flickering issues. This is a sequencer where the user always haves one selected track in full size and the other ones in a smaller size. But when I switch between tracks it flickers a bit. Basically I’m resizing the component inside the paint loop and using setVisible() to hide components like this:

[code]void MyComponent::paint (Graphics& g)  
{  
if (selectedTrackID==ACTIVE){  
setTopLeftPosition(0,0);  
setSize (800, selectedTrackSize);  
sequenceControlComponent-\>setVisible(true);  
patternComponent-\>setVisible(true);

```
}else{
    setSize (800, unselectedTrackSize);
    sequenceControlComponent->setVisible(false);
    patternComponent->setVisible(false);
}[/code]

```

Not sure if this is a design issue…?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 2, 2013, 6:52pm UTC](https://forum.juce.com/t/strange-flickering/9756/2 "2013-01-02T18:52:31Z")

</div>

Changing the size of your Component from inside the paint() function is a recipe for disaster. Don’t do it.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [January 2, 2013, 7:07pm UTC](https://forum.juce.com/t/strange-flickering/9756/3 "2013-01-02T19:07:13Z")

</div>

Always update (aka resized()) before you draw (aka paint() - which gets called if you resize anyways, if I’m not mistaken).

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [January 2, 2013, 7:14pm UTC](https://forum.juce.com/t/strange-flickering/9756/4 "2013-01-02T19:14:20Z")

</div>

I think what’s happening is he is missing a robust framework for broadcasting changes in meta UI settings (like currently selected track), and he’s relying on timer / paint calls to get the opportunity to perform the necessary user interface manipulation.

OP: Instead of doing this in the paint you should have a ListenerList, ChangeBroadcaster, or use one of the VFLib notification facilities:

[vf::componentNotifyParent](https://github.com/vinniefalco/VFLib/blob/master/modules/vf_gui/components/vf_ComponentNotifyParent.h) url=http://vinniefalco.com/VFLib/classcomponent\_notify\_parent.html[/url]  
[vf::componentBroadcast](https://github.com/vinniefalco/VFLib/blob/master/modules/vf_gui/components/vf_ComponentBroadcast.h) url=http://vinniefalco.com/VFLib/classcomponent\_broadcast.html[/url]

Probably componentBroadcast is what you want. For each of your Component objects that “cares” about the currently selected track, use multiple inheritance to derive it from this interface:

```auto
struct CurrentTrackListener {
  virtual void onCurrentTrackChanged (Track* currentTrack) { }
};
```

Then when the current track changes, broadcast the event from the top level:

```auto
vf::componentBroadcast (topLevelComponent, &CurrentTrackListener::onCurrentTrackChanged, currentTrack);
```

---

<div class="post-metadata">

**Author:** ![younameit](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/younameit/32/14165_2.png) [@younameit](https://forum.juce.com/u/younameit)\
**Post date:** [January 7, 2013, 2:42pm UTC](https://forum.juce.com/t/strange-flickering/9756/5 "2013-01-07T14:42:22Z")

</div>

Thanks guys, I will try this.

Cheers
