Why does my uicontextmenu only show after a pause/breakpoint?

1 次查看(过去 30 天)
I'm trying to show a contextmenu in a uifigure ontop of some uiaxes. On a mouseclick event, the function below is called to display the contextmenu.
This code runs fine, but when I remove the pause, the contextmenu stops showing. The location also seems to matter, if I put the pause any earlier in the code, no contextmenu shows up. Why is this happening? Are there any race-conditions I should be aware of?
function UOContextMenu(app, id, pos)
%Creates a contextmenu where the user clicked
%Input:
% app - the app
% id - id of the userobject
% pos - cursor position
%Find axis
axID = GUI.FindAxisAtPosition(app, pos);
axis = app.GetAxis(axID);
cm = uicontextmenu(app.UIFigure);
m1 = uimenu(cm,'Text','Delete');
m2 = uimenu(cm,'Text','Rename');
m3 = uimenu(cm,'Text','Copy To');
m4 = uimenu(cm,'Text','Toggle Visibility');
pause(0.1)
cm.Position = [pos(1), pos(2)];
cm.Visible = 'on';
axis.ContextMenu = cm;
return

采纳的回答

Jan
Jan 2023-1-24
Try to replace pause by drawnow. This allows the GUI to activate the updated properties. If this is working also, this is the expected and documented behavior. See: drawnow .

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by