Borrar filtros
Borrar filtros

UIContextMenu, callback and JmenuItem

3 visualizaciones (últimos 30 días)
William Maudru
William Maudru el 12 de Sept. de 2016
Editada: William Maudru el 12 de Sept. de 2016
Hello,
I am trying to use a contextmenu in a part of my main figure. On this part I have a tree and branches that I can expand. I can make appear the contextmenu using javax (according to my colleagues's code). here is my code to make appear the contextmenu :
function cb_treeMousePressed(~,eventData,handles)
% Set the mouse-press callback
if eventData.isMetaDown % right-click is like a Meta-button
% Get the clicked node
clickX = eventData.getX;
clickY = eventData.getY;
jtree = eventData.getSource;
% % Prepare the context menu (note the use of HTML labels)
menuItem1 = javax.swing.JMenuItem('Delete');
% % Set the menu items' callbacks
set(menuItem1,'ActionPerformedCallback',{@centralCallback, @cb_newDelete});
jmenu1 = javax.swing.JPopupMenu; % define menu for click on a model node
% entries of menu for model node
jmenu1.add(menuItem1); % add set as best to menu 1
% Set the tree mouse-click callback
% Display the context menu for model selection
jmenu1.show(jtree, clickX, clickY);
jmenu1.repaint;
end
end
But the problem is that when I am clicking on my Delet button of my contextmenu, Matlab says me :
Undefined function 'cb_newDelete' for input arguments of type 'java.awt.event.ActionEvent'.
Error while evaluating javax.swing.JMenuItem ActionPerformedCallback
Indeed my cb_newDelete is defined in my Callback section of my script. I don't want to implement again a new fuction. Do you know how can I do to re-use my cb_newDelete ? Even if I have to use something else than javax for my contextmenu, and if it is possible ?
Thank you in advance for your answers

Respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by