Dynamic updating UIContextMenu in figure window

Greetings -
Is there a way to update a string property in a UIContextMenu before it is called. I have plot with several lines on it all of whom have the same context menu assigned to them. I would like to update one of the strings in the context menu with some information from the line before the context menu appears. I don't however want to create a unique context menu for each line.
Thanks in advance for any help,
Brandon

回答 (1 件)

Jan
Jan 2012 年 7 月 20 日
編集済み: Jan 2012 年 7 月 20 日

0 投票

See http://www.mathworks.com/help/techdoc/ref/uicontextmenu_props.html : The 'Callback' function is processed immediately before the menu get visible.
FigH = figure;
UICH = uicontextmenu(FigH, 'Callback', @raiseContextMenu);
UserData.menu1 = uimenu(UICH, 'Label', 'not selected');
set(UICH, 'UserData', UserData);
line(1:10, rand(1, 10), 'ContextMenu', UICH);
line(1:10, rand(1, 10), 'ContextMenu', UICH);
...
function raiseContextMenu(UICH, EventData)
DlgH = ancestor(UICH, 'figure');
UserData = get(ObjH, 'UserData');
UserData.FigH = DlgH;
UserData.AxisH = get(DlgH, 'CurrentAxes');
UserData.LineH = get(DlgH, 'CurrentObject');
set(UserData.menu1, 'Label', datestr(now, 0));
set(UICH, 'UserData', UserData);
This methods stores the handles of the object, which has been active, when the context menu has been selected. Then all lines can share the same context menu and the actuall callbacks of the menu items cann access the UserData of the context menu.

2 件のコメント

Brandon
Brandon 2012 年 7 月 20 日
Looks like it is working. I was trying to do it with an "onclick" callback for the object which the uimenu was attached to.
Thanks
Iranga
Iranga 2013 年 10 月 15 日
編集済み: Iranga 2013 年 10 月 15 日
Could you pls answer this question?
if @raiseContextMenu has any outputs, how would you retrieve those from uicontextmenu?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

質問済み:

2012 年 7 月 20 日

コメント済み:

2013 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by