Is it possible to display a context menu without right click?

3 ビュー (過去 30 日間)
Mariale
Mariale 2016 年 1 月 26 日
回答済み: Dwight Bartholomew 2016 年 11 月 3 日
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

回答 (1 件)

Dwight Bartholomew
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);

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by