UICONTEXTMENU will not appear on GUI

11 Ansichten (letzte 30 Tage)
Lawson Hoover
Lawson Hoover am 9 Dez. 2012
I have been trying to get a context menu to appear anywhere on the eniter figure, which also has a plot on it. I have this code:
cmenu = uicontextmenu('Parent',S.fh);
bgmenu = uimenu(cmenu,'label','Background');
bg1 = uimenu(bgmenu,'Label','Grid','CallBack',set(imread,'filename','grid.jpg'));
bg2 = uimenu(bgmenu,'Label','ConTrail','Callback',set(imread,'filename','grid.png'));
bg3 = uimenu(bgmenu,'Label','Opera','Callback',set(imread,'filename','Opera.jpg'));
The Menu will not show up at all.

Akzeptierte Antwort

Matt Fig
Matt Fig am 9 Dez. 2012
Bearbeitet: Matt Fig am 9 Dez. 2012
You need to set the uicontextmenu property, not assign a parent.
S.fh = figure;
cmenu = uicontextmenu;
bgmenu = uimenu(cmenu,'label','Background');
set(gcf,'uicontextmenu',cmenu)
Now right click inside the figure....
  17 Kommentare
Matt Fig
Matt Fig am 9 Dez. 2012
I think you need to slow down and think it through. You have all of the pieces to get this working but you haven't quite seen it yet. It seems like you are trying to rush through without understanding what is going on.
Why would you think you had to load clown every time to make your GUI work? I did that as an example because I don't know what images you have on your disk but I do know you have the sample images MATLAB came with!! Scroll up to the example I posted and look at the comments where I explain this clearly.
You need to make sure that S.IH is plotted on the correct axes the first time you create it. Then changing the cdata will not move it to another axes.
Lawson Hoover
Lawson Hoover am 9 Dez. 2012
Bearbeitet: Lawson Hoover am 9 Dez. 2012
Ok so Im slowly getting it, you are loading clown and then saying it. But Clown is also a .mat right? so how would I save my images as a .mat? Also I have actually got the new image to appear on the back ground now, but instead of replacing it is just creating a new axes.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by