Label as custom TreeViewItem (showEditor())

Is there a way of having TreeViewItem::createItemComponent() return a Label component with its editor showing?

Calling showEditor() in createItemComponent() has no effect because the label has no parent and can’t take focus.

I’d like new items in my tree to be ready to receive names from the user.

Don’t forget that those components can be created at any time - e.g. when the treeview gets resized and needs more rows, when it scrolls, etc., so are you sure you want the label to always appear?

But I guess what I’d do would be to use the parentHierarchyChanged callback to show the editor when it gets put on the screen.

It’s a drag target too, so unfortunately, yes.

[quote]
But I guess what I’d do would be to use the parentHierarchyChanged callback to show the editor when it gets put on the screen.[/quote]

That’s workable. Cheers.

Is this still the recommended way to handle this or have things changed for this exact task? I’m using the componentParentHierarchyChanged() callback within a ComponentListener subclass to show the editor after the TreeViewItem is created but jassert (isShowing() || isOnDesktop()) is thrown in Component::grabKeyboardFocus() (with both conditions being false). Same when using componentVisibilityChanged().

Okay, can confirm this is the way to do it, just make sure to trigger the rename when component.isShowing() is true - not prematurely :slight_smile: