TreeCheckbox and Tab corelation in appdesigner
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Ravi
2023-12-5
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!