Renaming Item In A Tree

I have a TreeView that displays the names of things. How might I go about doing an in-place rename on them?. I’d like to do this similar to the way you can rename a file in the windows explorer. I looked for some examples but didn’t find any - suggestions would be welcome.

Hey kurt,

I guess On click you want to change name of that treeViewItem, Right ?
Using following method create custom item component with juce::component which has object of that treeViewItem inside it.
virtual Component * createItemComponent ()
Put one Label inside that component which has editing true,
Now When you click that item, start renaming that item, and update your component by repaint() method…

I hope you will get idea of waht to do with above description …
Have Fun …

AhHa! - I see what you mean, thank you - I’ll try to return the favor when I get more experience with juce. Right now I’m asking more than I’m responding.

You are welcome friend …
You know we are sharing what we know,
And always we feel good helping . Have fun .


Well I got the createItemComponent() working with a label however…The problem I’m having now is that I want to preserve the original treeview ‘item selected’ callback capability as well as being able to do the rename. In other words I need a click on the treeviewitem to select a song, AND allow renaming when the mouse is clicked again on the item.

Now I did pass the treeviewitem into my class SongLabel public Label, thus I can call the itemClicked method from an overridden mouseDown, but the problem is getting gnarlier as I need to paint, and not-paint the background when the item is selected & de-selected etc. It appears I can do this but is there an easier way to preserve BOTH behaviours?

Thanks Folks,

Well, I made some progress - Given a TreeView, and TreeViewSongItem (previous known as TreeViewDemoItem), which displays ‘songs’ (by name) and desiring that selecting a tree item ‘changes songs’ while allowing renaming of song item…

I was mistakenly (I think), doing song selection in the itemClicked() override, which wasn’t being called when I instantiated a Label for the treeView Component. I am now doing song selection in itemSelectionChanged(bool), which is being called…Thus in the code below, I probably don’t need to call itemClicked, or itemDoubleClicked, but the code relating to changing the background color IS needed, and I think I also must call the treeviewItem.setSelected() method…

In any case, I THINK I have both behaviors working now…but still…Am I going about this in the ‘right’ way?
Suggestions? Improvements?

SongLabel::SongLabel (TreeViewItem& treeViewItem, const String &componentName, const String &labelText)
    : Label (componentName, labelText),
    //setSize (600, 400);
	originalBackground = findColour(Label::backgroundColourId);


void SongLabel::paint (Graphics& g) {
	if( tvItem.isSelected() ) {
		setColour(Label::backgroundColourId, Colours::orange.withAlpha (0.75f));
	} else {
		setColour(Label::backgroundColourId, originalBackground);

void SongLabel::mouseDown (const MouseEvent &e) {
	tvItem.setSelected(true, true);

void SongLabel::mouseDoubleClick (const MouseEvent &e) {
	tvItem.setSelected(true, true);
1 Like