Give focus to the component from createItemComponent()

My goal is to allow the user to add a new item to a tree, and give focus to that item’s component so that the user may begin editing it. My code in createItemComponent() looks something like this:

   Label *label= new Label("NewLabel", "");
   return label;

The editor shows, but without focus. It looks like it’s losing focus when addAndMakeVisible is called on it in TreeViewContentComponent::updateComponents(). Is there any way to give it focus outside of createItemComponent?

Well, that’s not too surprising - when you create the label it’s not actually on the screen yet, so can’t possibly have the focus until after your method has returned it… You’d need to create some sort of async event that will occur after the label has been added, and will make it open its editor. I just did something similar in my new jucer code, and it’s a bit fiddly, but does work.