Why does my uicontextmenu only show after a pause/breakpoint?
2 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!