"Mirrored" or "Ghost" component


Is there a simple way to draw a single component instance in two places, so that both visual entities act as if they were one?


You can’t really create two instances of the ‘same’ component in two places but you can certainly have two unique components share an underlying data structure. Take a look at how most of the standard JUCE widgets work (e.g. sliders, comboboxes, labels etc.), they all contain a Value object that corresponds to their value. These can be shared between components so in proper MVC style changing one updates the others. The JUCE demo does this very nicely on the widgets page.

If you need more complex components take a look at using a ValueTree for your data and respond to changes in that.


Thanks for the tip, Dave. I can see how this works for basic components, like sliders and combo boxes, but what about a TreeView for example? The TreeView has getOpennessState and resoreOpennessState methods, but no value accessor to set common underlying state information.


Where’s the treeview getting the underlying state from? That’s where your second treeview gets its data.


I think that what he meant here is that sharing the underlying Model here is not sufficient, because the openness state of each node in the treeview pertains the View side of the MVC pattern and thus two components that share the same Model still can “look” different on the UI according to how the user has interacted with them (opening and collapsing different nodes in this case).



The tree is built from an XML document, but the current tree state is data contained in the TreeView instance.

I have 2 trees. The processor can be put into a “linked” mode. When in this mode, I’d like the trees to follow one another. When not in linked mode, the trees can act independently. I’m still trying to fathom the neatest way to approach this.

If the TreeView was value-class compatible, I could have something like this . .


//Unlinked callback

//Link mode set callback