I am working in Matlab. I want to show Images in a given Panel one by one when user mouse click on a file name in tree list. Can anyone please help me?
Code for tree:
src = strcat(pwd,'\Result\');
[mtree, container] = uitree('v0', 'Root',src,۔۔۔
'Position',[10 10 290 370],'Parent', imageListPanel2); % Parent is ignored
set(container, 'Parent', imageListPanel2); % fix the uitree Parent
Function to Display Image in panel:
function refreshDisplay(varargin)
imgDisplayed = imshow(tmp,'parent',workingAx);
end %refreshDisplay
I just need to know how to call function refreshDisplay() from my tree. Again remember I want to call function from Tree Elements(files) not from node(sub directory).
Regards.
Note that everything in the tree are nodes, both the folders and the images. You need to implement a check inside the selection callback to test whether the selected node is a folder.
Quoting UndocumentedMatlab:
The currently-selected node(s) can be accessed using mtree.getSelectedNodes. Node selection callbacks often require knowledge of the currently selected rows:
%// Tree set up
mtree = uitree(..., 'SelectionChangeFcn',@mySelectFcn);
set(mtree, 'SelectionChangeFcn',@mySelectFcn); % an alternative
%// The tree-node selection callback
function nodes = mySelectFcn(tree, value)
selectedNodes = tree.getSelectedNodes;
%// Use this to see which information is available about the node:
%// methods(selectedNodes(1),'-full')
%// And the node array:
%// methods(selectedNodes,'-full')
if ~isempty(selectedNodes) || max(selectedNodes.size)>1
%// Obtain path from selected node; Source: link1 below
nodePath = selectedNodes(1).getPath.cell;
subPathStrs = cellfun(@(p) [p.getName.char,filesep],nodePath,'un',0);
pathStr = strrep([subPathStrs{:}], [filesep,filesep],filesep);
%// Also, don't forget a drive letter here ^ if required
if ~isdir(pathStr) %// check that the selection isn't a directory
%// this is where you need to call your refresh function
end
end
end %// mySelectFcn
You can get some other ideas in this answer, which shows how to implement a mouse tracking callback, in case you want the refresh to execute on a mouse-over...