필터 지우기
필터 지우기

UIContextMenu, callback and JmenuItem

조회 수: 3 (최근 30일)
William Maudru
William Maudru 2016년 9월 12일
편집: William Maudru 2016년 9월 12일
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

답변 (0개)

카테고리

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