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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Jan
Jan il 24 Gen 2023
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 .

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by