View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 7.46 KB File ID: #31448 Version: 1.4
image thumbnail



Igor (view profile)


14 May 2011 (Updated )

Simple way to show contextmenu on left click in a nice drop-down way.

| Watch this File

File Information

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'

MATLAB release MATLAB 7.12 (R2011a)
Other requirements Not tested,but should work with even quite outdated versions.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
22 Jun 2012 Igor

Igor (view profile)

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...

Comment only
22 Jun 2012 Brett Shoelson

Brett Shoelson (view profile)

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.

Comment only
18 May 2011 nsbd

nsbd (view profile)

17 May 2011 Igor

Igor (view profile)

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.)

Comment only
16 May 2011 Loginatorist

Loginatorist (view profile)

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.

Comment only
17 May 2011 1.2

+support for lines etc. (objects without 'units' property (menu would be displayed on click position)
+"assert" removed with if..error

27 May 2011 1.3

Thanks to Jesse this now supports uipushtool and uitoggletool objects (toolbar items).
usage example provided in test_showcontextmenu3.

21 Jun 2012 1.4

added test_showcontextmenu4:
in this example, in contrast to test_showcontextmenu, right-click menu is shown below the button (not on click position)

Contact us