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

4 Ansichten (letzte 30 Tage)
Mus'ab Ahmad
Mus'ab Ahmad am 22 Feb. 2017
Bearbeitet: Mus'ab Ahmad am 22 Feb. 2017
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.

Antworten (1)

Adam
Adam am 22 Feb. 2017
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 Kommentar
Mus'ab Ahmad
Mus'ab Ahmad am 22 Feb. 2017
Bearbeitet: Mus'ab Ahmad am 22 Feb. 2017
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'

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps 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!

Translated by