Unknown handles in uitree, mouse press callback

Dear my friend
I have a question about handles
I designed a GUI with a uitree, I decided to implement the mouse pressed call back which is one of the properties of uitree (javahandles) but handles is unknown by the callback.
This problem makes too many difficulties in my coding and actually stopped me from continuing the programming.
I really ask you how i can access thehandles in mouse pressed callback which is one of the events of the uitree (javahandles)?
Thanks in advance

2 Comments

hamid - you may need to post some of your code so that we can get a better idea as to what you have attempted and how the mouse press callback has been implemented. Have you used GUIDE to create your GUI?
Thanks a lot because of your consideration to my problem ....
First, I describe briefly what i aim to achieve, actually i have a push button for adding different data in order to show them in the axes, the list of data then would be added to the hierarchy structure of uitree.
I want to erase the axes of any layer which the the layer is unckecked in the uitree and then show that specific layer when it was checked again ....
in the code below
i used a switch case, as the node is checked or unchecked, whether it is unchecked i erased the axes, on the contrary when it is checked i should show that specific layer. H
ere is the problem, i can not send the handles as an argument to the function for showing the layer ....
function mousePressedCallback(hTree, eventData) %,additionalVar)
% if eventData.isMetaDown % right-click is like a Meta-button
% if eventData.getClickCount==2 % how to detect double clicks
% Get the clicked node
global jtree;
global iconWidth;
global javaImage_checked;
global javaImage_unchecked;
global ha;
% global nodesCellReverse;
% global stateCellReverse;
% global layerPath;
% global tickbg;
clickX = eventData.getX;
clickY = eventData.getY;
treePath = jtree.getPathForLocation(clickX, clickY);
% check if a node was clicked
if ~isempty(treePath)
% check if the checkbox was clicked
if clickX <= (jtree.getPathBounds(treePath).x+iconWidth)
node = treePath.getLastPathComponent;
nodeValue = node.getValue;
% as the value field is the selected/unselected flag,
% we can also use it to only act on nodes with these values
switch nodeValue
case 'selected'
node.setValue('unselected');
node.setIcon(javaImage_unchecked);
jtree.treeDidChange();
% handles.indexSelected=1;
%----Har Vaght Kasi Omad va En Tick ra bardasht,Safhe ra Kamel Pak kon
if isempty(node.getPreviousSibling)
%faghat agar avlin tick ra bardasht safhe ra pak
%konad
cla(ha);
%chon enja ma faghat darim layer 1 ra neshan midahim
%migim, agar taraf tick ra bardasht, va en tick,
%tick aval bod ye code shenasayiii be en vazeyat
%ekhtesas midahim
% tickbg=15;
end
case 'unselected'
node.setValue('selected');
node.setIcon(javaImage_checked);
jtree.treeDidChange();
% if tickbg==15
% %Yani agar taraf tick ra bardasht va en tick avalin
% %layer bod, bayad bad az tick zadan e mojadad layer
% %ra neshan bedahim
% traverseLayersUitree(nodesCellReverse,stateCellReverse,layerPath,handles);%dar hale hazer ke path
% %ya masoir ma yekist moshkeli ejad nemikone ama agar
% %chand masir bashe moshkel ejad mikonad
% end
end
end
end
Hope it was complete and clear
Again, thanks for your attention ...

Sign in to comment.

Answers (1)

When you create a callback yourself, you need to pass in the handles structure. For example,
set(handles.AppropriateTagHere, 'SelectionChangeFcn', @(src, event) mySelectFcn(src, event, handles))
Note that when you do this, a copy of handles will be taken and it will always be that same copy that is passed to the function call, not being updated if you change data fields in handles. If your handles structure contains handles to graphics objects, then you will be able to see changes that happened to that object, as long as the handle to the graphics object remains valid.

2 Comments

Thanks Walter
but i did not completely catch where i should put this command and what is the AppropriateTag? and the 'SelectionChangeFcn' is my own function or is something else? and also give me more information about the command you provided it is some how difficult to understand ....
Thanks alot
You did not happen to show the code in which you set mousePressedCallback to be used.
% MousePressedCallback is not supported by the uitree, but by jtree
set(jtree, 'MousePressedCallback', @mousePressedCallback);
You would alter that to
% MousePressedCallback is not supported by the uitree, but by jtree
set(jtree, 'MousePressedCallback', {@mousePressedCallback, handles});
and you would alter
function mousePressedCallback(hTree, eventData) %,additionalVar)
to
function mousePressedCallback(hTree, eventData, handles)

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 30 Sep 2016

Commented:

on 1 Oct 2016

Community Treasure Hunt

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

Start Hunting!