# TreeView: reacting on mouse up's

**URL:** <https://forum.juce.com/t/treeview-reacting-on-mouse-ups/7731>\
**Category:** General JUCE discussion\
**Created:** [November 18, 2011, 11:20am UTC](https://forum.juce.com/t/treeview-reacting-on-mouse-ups/7731 "2011-11-18T11:20:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zamrate](https://avatars.discourse-cdn.com/v4/letter/z/f4b2a3/32.png) [@zamrate](https://forum.juce.com/u/zamrate)\
**Post date:** [November 18, 2011, 11:20am UTC](https://forum.juce.com/t/treeview-reacting-on-mouse-ups/7731/1 "2011-11-18T11:20:17Z")

</div>

Right now, there’s only TreeViewItem::itemClicked(). Would it be possible to enhance this so it would contain: itemMouseDown(), itemMouseUp() ?  
I tried all sorts of stuff using a MouseListener but it crashes, my code was like this:

[code]  
class MyTreeViewItem:public TreeViewItem, public MouseListener  
{  
void itemClicked(const MouseEvent &e)  
{  
e.originalComponent-\>addMouseListener(this, false);  
…   
}

```
void mouseUp(const MouseEvent &e)
{
    e.originalComponent->removeMouseListener(this);
    ...
}

```

}[/code]

… and somehow, when I drag’n’drop the TreeViewItem onto another DragAndDropTarget, then I get a crash (access violation) in Component::MouseListenerList::sendMouseEvent() after releasing the mouse button, in this line:

```auto

```

Maybe there’s another, simple solution? Thanks for help.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 18, 2011, 12:37pm UTC](https://forum.juce.com/t/treeview-reacting-on-mouse-ups/7731/2 "2011-11-18T12:37:53Z")

</div>

I’m going to add a comment in the TreeViewItem code saying “No, I will not be adding any more f\*\*king callbacks to this class!” as I’m getting tired of answering this same kind of request!

If I added itemMouseUp, then people would ask for imageMouseWheel… then itemKeyDown, etc. etc and eventually it’d end up as big as the component class. If you need fancy behaviours, you should use TreeViewItem::createItemComponent().

---

<div class="post-metadata">

**Author:** ![zamrate](https://avatars.discourse-cdn.com/v4/letter/z/f4b2a3/32.png) [@zamrate](https://forum.juce.com/u/zamrate)\
**Post date:** [November 18, 2011, 12:59pm UTC](https://forum.juce.com/t/treeview-reacting-on-mouse-ups/7731/3 "2011-11-18T12:59:59Z")

</div>

I know there’s createItemComponent(), I just didn’t want to create 1 Component per Item, because this could generate thousands of Components. I don’t think it would make the TreeView as responsive. I just wanted a mouseUp notification, because when the Item is clicked, it should start playing audio, and when mouse is released it should just stop audio.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 18, 2011, 1:30pm UTC](https://forum.juce.com/t/treeview-reacting-on-mouse-ups/7731/4 "2011-11-18T13:30:17Z")

</div>

It’ll only create components for the on-screen items in the tree (unless I’ve mis-remembered how it works…)
