Is it possible to display a context menu without right click?
3 ビュー (過去 30 日間)
古いコメントを表示
In the case that this is no possible, how can I display a menu similar to the uicontextMenu when the user makes a left click on a Figure. 'uimenu' doesn't work because I don't want a bar menu. I just want to display a menu when the user left clicks on a specific place on the figure. Thanks
0 件のコメント
回答 (1 件)
Dwight Bartholomew
2016 年 11 月 3 日
I had the same issue with a table. Solution was a Java robot. If hTable is the handle for the table then I set up a context menu, for example,
cmenu=uicontextmenu;
uimenu(cmenu,'label','Context Menu #1');
uimenu(cmenu,'Label','Context Menu #2');
uimenu(cmenu,'Label','Context Menu #3');
and assign it to the table with set(hTable,'uicontextmenu',cmenu);
I also have a callback when a cell of the table is selected set(hTable,'CellSelectionCallback',@SelectCell);
Within the SelectCell function, I use a Java Robot to simulate a right-click which initiates the context menu. NOTE - I had to put a 0.2 second pause between "press" and "release" and for anything shorter than 0.2 seconds the system either didn't see the click or was intermittent is seeing the click.
% Simulate a right-click with the mouse
import java.awt.*;
import java.awt.event.*;
mouse = Robot;
mouse.mousePress(InputEvent.BUTTON3_DOWN_MASK);
pause(0.2);
mouse.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
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!