Assigning a context menu to a UIAxes
Show older comments
I am using appdesigner with Matlab 2020b.
I have a UIAxes in the main window, and I would like to assign a context menu to that axis.
I have implemented the context menu, and I can attach it to the 'panel' that contains the UIAxes. The axis functions correctly when I right-click on the panel around the UIAxes.
But I cannot attach the context menu to the UIAxes itself. The menu only appears when I right-click on the panel, not on the UIAxes.
The context menu is assigned to the UIAxes (see attached PNG file).
Brian Wandell
wandell@stanford.edu
(lmperry@stanford.edu is the name of my lab manager. I would appreciate if you could make sure the message is also sent to my account).
Accepted Answer
More Answers (2)
Brian Wandell
on 9 Nov 2020
1 Comment
Mario Malic
on 9 Nov 2020
If you click on an image, you would be clicking on one of the children which is most probably child of UIAxes.
if isa(event.Source,'matlab.ui.Figure') % this works for UIFigure and figure - unnecessary
if isa(event.Source.CurrentObject,'matlab.graphics.primitive.Image') % same as below?
if isequal(event.Source.CurrentObject.Type,'image') %
% open(app.ContextMenu, 250, 250);
open(app.imageMenu,250, 250);
Function open, opens context menu https://www.mathworks.com/help/matlab/ref/matlab.ui.container.contextmenu.open.html
You also need to implement a right click, see my last comment.
If you have only one axes that you want to do something with, you can try with only selection type.
Brian Wandell
on 10 Nov 2020
1 vote
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!