[FR] Buttons: add option to ignore clicks with right mouse button


What I wish to do is have a Button display a context menu when right-clicked.

A MouseListener attached to it takes care of displaying the PopupMenu just fine.

The problem is that the Button still receives its “click” event when the right mouse button acts upon it, which is something I don’t want in my use case.

Would it be possible to add an option to the base Button class to avoid that?

EDIT: if it is of any help, this is the patch with which I have hardcoded that behavior (left-click only) in my local JUCE repo. It is provided only to show the sole three lines that would require intervention: left-click-only.txt (1.9 KB)

Button right click confusion



I had to write a subclass just for this purpose.


Surely that’s why we have the other clicked() method that provides the modifier keys?



I’m not sure you understood our use case Jules. here is a example :

you have a large component that contains many children buttons of all kind (textButtons, toggleButtons, etc…)
you want the user to be able to right click anywhere on that parent component to open a contextual menu.
at the moment, if the right click happens over a button, you will get the contextual menu, but the underlying button will also get clicked (and we don’t want that)

so we were more looking for something like a Button::setIgnoreRightClicks() or an additional flag to setInterceptClicks(). for now we have to inherits the buttons class.

I ended up doing something like that :

template <typename ButtonType>
struct ButtonIgnoringRightClick : public ButtonType
    using ButtonType::ButtonType;

    void mouseDown (const MouseEvent& e) override
        if (e.mods.isPopupMenu())

        ButtonType::mouseDown (e);

    void mouseUp (const MouseEvent& e) override
        if (e.mods.isPopupMenu())

        ButtonType::mouseUp (e);

ButtonIgnoringRightClick<TextButton> myTextButton;

Get rid of right-click clicking

What about things like HyperlinkButton that open the link with a right click? Or ToggleButtons that change state with a right click? Neither of those make any sense from a UX perspective. Of course it’s not the end of the world to sub-class, but equally would it really be the end of the world to implement something like Button::setIgnoreRightClicks() or similar?
Unless I missed something about those particular examples that can stop them behaving in that odd manner.