File Exchange

image thumbnail


version (7.46 KB) by Igor
Simple way to show contextmenu on left click in a nice drop-down way.

1 Download

Updated 21 Jun 2012

View Version History

View License

Use as follows:
hcmenu1 = uicontextmenu;
Try test_showcontextmenu.m for usage example.

This also contains a number of trivial routine functions:
%returns hObject's parent figure

getPositionOnFigure( hObject,units )
%returns absolute position of object on a figure

getRelPosition( hObject,units )
%get(hObject,'Position') with specific 'units'

getCurrentPoint( hFigure,units )
%get(hFigure,'currentpoint') with specific 'units'

Cite As

Igor (2021). showcontextmenu (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)


Hi Brett,
thank you!

Concerning FINDALL, are you talking about
test_showcontextmenu3.m line 9?

You're right, and the thing is
get(tbh,'HandleVisibility') == 'off'
that's why we have to use FINDALL...

Brett Shoelson

I haven't tried this yet, Igor, though it looks interesting. I'm intrigued by your use of normalized units, and of the steps you had to take to make this all work in them. (I'm a fan of normalized units, too, and have done similar things.)

Also, I wanted to point out that FINDALL (as opposed to FINDOBJ) returns all children of a specified object, including those whose handles are hidden.



Thanks for your comment,Matt.
I've updated the submission so that it can now handle line as object.

(However I'm still not sure this would work for all such objects (without 'units') since 'current point' seems unreliable in case of button at least.)

Matt Fig

This function will error on versions of MATLAB which do not have ASSERT. For example 2006a.
Also, if the handle of the object does not have a 'units' property, the function errors. A line, for example, may have a uicontextmenu, but does not have a 'units' property.

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!