TreeCheckbox and Tab corelation in appdesigner
10 views (last 30 days)
Show older comments
Hello, I am working on a gui project and everythings are all new for me. I have main tab which name is Sea State, in this tab ı have button(add target) and TreeCheckBox(shows target names). Whenever I push the button, targets are adding as a checkbox under the tree with Target 1 , Target 2 .. Target names(n shows how many times I pushed). Everything all good untill here.Anyway, I am trying to after I check the checkbox, I wanna create new Tab with the same name with checkbox. I searched but I couldnt solution. Thanks from now.
0 Comments
Answers (1)
Ravi
on 5 Dec 2023
Hi Aybars,
I assume the problem you are facing is you are not able to create a tab with the name of the checkbox you are checking. Here is a potential solution for the issue.
% Selection changed function: Tree
function TreeSelectionChanged(app, event)
selectedNodes = app.Tree.SelectedNodes;
for idx = 1:length(selectedNodes)
tabName = selectedNodes(idx).Text;
if ~any(strcmp(app.tabNames, tabName))
newTab = uitab(app.TabGroup, 'Title', tabName);
app.tabNames = [app.tabNames, tabName];
end
end
end
Whenever you check a checkbox, a callback should be called which here is the “CheckedNodesChangedFcn” callback. In this solution, I have a function “TreeSelectionChanged” that is triggered when a checkbox is clicked. In the function, we obtain the list of all selected checkboxes. We loop over the checkboxes, and check if a tab already exists with the name of the current checkbox. If it does not exist already, then we create a tab group.
We maintain an array called “tabNames” that stores the names of the tabs that are already created. When we create a new tab, we add that name to the “tabNames” array.
For more understanding on the callbacks for tree checkbox in MATLAB, please go through the attached resources on “uitree”: https://www.mathworks.com/help/matlab/ref/uitree.html
Hope this solution helps you fix the issue you are facing.
Thanks,
Ravi Chandra
0 Comments
See Also
Categories
Find more on Search Path in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!