Is there a way to safely 'refresh' the component returned from TreeViewItem::createItemComponent()


Hi all,

Is there a way to safely refresh the Component I returned from TreeViewItem::createItemComponent()?

According to the docs I am not allowed to keep a reference to it, but I do need to call its refresh() function. A simple repaint will not do, as refresh() updates the text of a label and somewhat more. I would also like to add drag-and-drop support later on, so I do need to use createItemComponent() instead of paintItem().

As usual, any help is much appreciated!


You're thinking about it the wrong way round..

If this component needs to be updated when something changes, then the component should register itself as some kind of listener with the thing it represents, and update itself when that thing changes.


Yeah, well, the data format the tree represents isn't written with a listener pattern in mind, and I'd like to keep that out as much as possible in a MVC kind-of way. Doesn't really mesh with the rest of the non-JUCE codebase.

Having said that, I now have the derivative of TreeView keep listeners and have the aforementioned components add and remove themselves upon construction/destruction. Works.

Thanks for the advice!