Get mouse clicks for ValueTree

I have looked for examples, but I either do not understand them, or nothing has been found.

Simply, I have a ValueTree, properly being populated. Now I want to be notified when a user right mouse clicks on a node. I wish to open a menu giving some actions that can performed.

Am I missing something obvious and will someone set me straight, please?


Thanks, but this needs more than RTFM. I have been over and over and it seems to say it will do it, but my attempts give nothing.

To make it simple, I am trying to work with the ValueTreesDemo.cpp as part of the Demo example. I have added this to the class:
class ValueTreesDemo : public Component, public DragAndDropContainer, private ButtonListener, private MouseListener, private Timer

Then added this:
void mouseUp ( const MouseEvent &ev ) override
int x = 1;
x += 3; // set breakpoint on this line

The int x stuff is simply so Studio will give me a breakpoint.

I run the demo and the ValueTree is populated the way I desire but clicking, with right or left does not hit my breakpoint. I know there is no bug and that I am not doing it properly. I am hoping someone can show me the code to get mouse clicks in that ValueTreeDemo. Thanks in advance.

FYI, I am porting a C# app and it gives me hover, mouse up, mouse down, and mouse move. All I need here is mouse up, but most likely once I figure that out, the others will be easy.

You use a TreeView to display your ValueTree… once you have your TreeView ‘Component’ you can get mouse clicks, etc.


OK, it is working after adding:

tree.addMouseListener ( this, true );

Now to figure out which button and the TreeView node.

Thanks for your hellp.

Adding raw mouse listeners yourself to the treeview is a really bad idea. What you really want to be doing is using the TreeViewItem::itemClicked() callback.

Thanks Jules. This is a learning experience and I’m slowly getting it. Could you explain in a few sentences why it is a bad idea and when it would be appropriate?

BTW, I moved some things and now am using the TreeViewItem::itemClicked() callback as suggested. My routine works just fine.

Continuing with the expedition, but have hit a stumbling block.

As the ValueTree is being built I would like to attach a small graphic to the TreeViewItem in the way that the fileTreeComp does in the TreeViewDemop.cpp (part of the Juce Demo example). It uses a folder image and a file image, which is great so you know what you have.

It seems that the ValueTree is built and then it uses the TreeView to be displayed. I deduce this because as the ValueTree is being built the TreeView rootItem is NULL.

I don’t require the graphic but it would be a nice visual clue as to the type of database item.