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

6 visualizaciones (últimos 30 días)
Mariale
Mariale el 26 de En. de 2016
Respondida: Dwight Bartholomew el 3 de Nov. de 2016
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

Respuestas (1)

Dwight Bartholomew
Dwight Bartholomew el 3 de Nov. de 2016
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);

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by