필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Cyrano Chatziantoniou
Cyrano Chatziantoniou 2023년 1월 24일
답변: Jan 2023년 1월 24일
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