Create sub-tabs inside main tabs ('Parent' property problem)

조회 수: 3 (최근 30일)
Mus'ab Ahmad
Mus'ab Ahmad 2017년 2월 22일
편집: Mus'ab Ahmad 2017년 2월 22일
I managed to create gui that has variable number of main tabs based on some extracted data from an XML file using this code
if true
% code
Maintabgp = uitabgroup(gcf);
for x = 1: ActNo %create the number of tabs based on some calculations to find ActNo
MainTabs.(['MainTab' num2str(x)]) = uitab(Maintabgp,'Title',['Actuator' num2str(x)]);% For example, if ActNo = 4 then MainTabs: 1x4 cell = [1x1 Tab] [1x1 Tab] [1x1 Tab] [1x1 Tab]
end
And now I want to create 5 sub tabs inside each main tab but I can't assign the 'Parent' of the SubTabgp as illustrated below
if true
% code
Maintabgp = uitabgroup(gcf);
for x = 1: ActNo %create the number of tabs based on some calculations to find ActNo
MainTabs.(['MainTab' num2str(x)]) = uitab(Maintabgp,'Title',['Actuator' num2str(x)]);% For example, if ActNo = 4 then MainTabs: 1x4 cell = [1x1 Tab] [1x1 Tab] [1x1 Tab] [1x1 Tab]
Subtabgp = uitabgroup('Parent','???');
AppSubTab = uitab(Subtabgp,'Title','App','Parent','???');
SpecsSubTab = uitab(Subtabgp,'Title','Specs','Parent','???');
OpSubTab = uitab(Subtabgp,'Title','Op','Parent','???');
TrnsSubTab = uitab(Subtabgp,'Title','Trns','Parent','???');
ActEnrgySubTab = uitab(Subtabgp,'Title','ActEnrgy','Parent','???');
end
Also, the 'Parent' property must be assigned for each sub tab in order to be able to create ui components inside each sub tab, and properly provoke the callback functions.

답변 (1개)

Adam
Adam 2017년 2월 22일
You just need to give the parent tab e.g.
AppSubTab = uitab(Subtabgp,'Title','App','Parent', MainTabs.MainTab1 );
If you want an AppSubTab within each of your main tabs you will have to create one for each of them as you can't share one tab between both. Well, you can if you keep reparenting it when you switch tabs - this can be a workable solution, but it depends what is on the tab and whether you need to remember its state on the previous main tab to switch back to etc as to how complicated that is.
  댓글 수: 1
Mus'ab Ahmad
Mus'ab Ahmad 2017년 2월 22일
편집: Mus'ab Ahmad 2017년 2월 22일
This creates one for each
MainTabs_SubTabs = MainTabs.(['MainTab' num2str(x)]);
Subtabgp = uitabgroup('Parent', MainTabs_SubTabs);
AppSubTab = uitab(Subtabgp,'Title','App','ButtonDownFcn',@CurntSubTab);
but with each new main tab the new subtabs replace the previous ones, so any callback functions will have effects on the subtabs of the LAST main tab because the subtabs of the other main tabs are no longer exist.
function CurntSubTab(hObject,handles)
global Subtabgp
global crntSubTab
crntSubTab = Subtabgp.SelectedTab
display 'subtab selected'

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by