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

回答(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 CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by