How do I insert a tree object generated by external function into App Designer?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am new to GUI and am really struggling to figure out these parent and container things. I generated a uitree object using an external function struct2tree
function [tree,container] = struct2tree(S,h)
%STRUCT2TREE renders the given structure as a uitree object
% [TREE,CONTAINER] = STRUCT2TREE(S) returns the uitree object and its
% container object rendered in the current figure.
%
% ... STRUCT2TREE(S,H) renders the uitree in the given container.
%Example
%
% [tree,container] = struct2tree(S,gcf);
% set(tree,'NodeSelectedCallback',@myNodeSelectedCallback)
% set(container,'units','normalized','position',[0 0 1 1])
if nargin==1,h=gcf;end
if isscalar(S)
root = struct2node(S);
else
root = uitreenode('v0','Root','Root',[],false);
name = inputname(1);
arrayfun(@(x)root.add(struct2node(x,name)),S);
end
% [tree,container] = uitree('v0','Root',root);
[tree,container] = uitree('v0','Root',root);
set(container,'Parent',h)
And I want to display this tree in my app in App Designer, which already has an app.Tree object. No matter what inputs I use, it either generates the tree in another figure window (see below) or produces an error, wrong parent object or something.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1020455/image.png)
What inputs and outputs should I use to make it appear in my app?
1 Kommentar
Walter Roberson
am 3 Jun. 2022
What is the error when you pass the existing uitree as the second parameter to struct2tree()?
Antworten (2)
Tushar
am 27 Sep. 2023
Hi Shao-Yu,
I understand that you are looking to create a new 'uitree' in your app using App Designer, and you already have an 'app.Tree' object. I would recommend using the 'Design View' of the App Designer to effortlessly incorporate 'uitree' components into your app. Here are the step-by-step instructions:
- Open App Designer by clicking 'Design Apps' in the 'Apps' section of MATLAB.
- Create a new project.
- Navigate to the 'Design View' section of the app.
- From the 'Component Library,' simply drag and drop the 'Tree' or 'Tree (Check Box)' component onto your app.
- Construct the tree object by adding 'Child' or 'Sibling' nodes. Right click on any node and select the desired option.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1494352/image.png)
- The nodes can be renamed from the ‘Tree Node’ section located in the bottom right corner of the interface.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1494357/image.png)
- Multiple 'uitree' objects can be added by dragging and dropping another 'Tree' from the 'Component Library'.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1494362/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1494367/image.png)
By following these steps, a tree object can be seamlessly integrated into an App Designer project, even if a 'app.Tree' object is already present.
For further information, please refer to the following documentation links:
Hope this helps!
0 Kommentare
prabhat kumar sharma
am 17 Jan. 2024
So I have tried creating a UITree using struct2tree and found out it opens a new figure instead of the already existing app when a single argument struct is passed in the function call 'struct2tree(S)'.
While this function provides the functionality to pass another argument 'h' that is the handle for the figure where you want to add your UITree. As if we don't pass the second argument by default in the implementation of struct2tree h is defined as:
h = gcf
gcf is use to get the handle of the current opened figure.
So it create a new figure.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1592736/image.png)
When I tried passing the handle for the app using
struct2tree(S,app.UIFigure)
then I encountered below error.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1592741/image.png)
So what I understood is , It currently does'nt support to pass the handle for the app designer based figure. On further research I found out.
To use the struct2tree function from the File Exchange to populate a uitree in your App Designer GUI, you would need to adapt the code provided by the struct2tree function to work with the uitree and uitreenode objects in App Designer. The struct2tree function likely creates a Java-based tree, which is different from the uitree object in App Designer.
I'll suggest to use the app designer's UITree component available in component library to embed in the app.
I hope it helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!