How do I insert a tree object generated by external function into App Designer?

18 views (last 30 days)
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.
What inputs and outputs should I use to make it appear in my app?

Answers (2)

Tushar
Tushar on 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.
  • The nodes can be renamed from the ‘Tree Node’ section located in the bottom right corner of the interface.
  • Multiple 'uitree' objects can be added by dragging and dropping another 'Tree' from the 'Component Library'.
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!

prabhat kumar sharma
prabhat kumar sharma on 17 Jan 2024
I assume that you tried to create a UITree using the struct2tree library provided here.
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.
When I tried passing the handle for the app using
struct2tree(S,app.UIFigure)
then I encountered below error.
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!

Categories

Find more on Dates and Time in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!