MATLAB Answers

uitabgroup with tabs from different .fig files

8 views (last 30 days)
Joakim Magnusson
Joakim Magnusson on 14 Jun 2016
Edited: Joakim Magnusson on 14 Jun 2016
I have created a GUI with "tabs" with just buttons. When I push a button I just make the current figure invisible and the selected figure visible. I would like to change it and use uitabs in matlab r2015b instead, now to my question. Is it possible to make the tabs in different .fig - files and have the uitabgroup in a main figure? I have made som tries but I can't see how it can be done.
Example
%Create tab group
handles.tgroup = uitabgroup('Parent', handles.figure1,'TabLocation', 'left');
handles.tgroup2 = uitabgroup('Parent', handles.figure1,'TabLocation', 'left');
handles.tab1 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 1');
handles.tab2 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 2');
handles.tab3 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 3');
%Place panels into each tab
set(handles.p1,'Parent',handles.tab1)
set(handles.p2,'Parent',handles.tab2)
set(handles.p3,'Parent',handles.tab3)
%Reposition each panel to same location as panel 1
set(handles.p2,'position',get(handles.p1,'position'));
set(handles.p3,'position',get(handles.p1,'position'));
Something like this but instead make handles.tab2 and handles.tab3 in other .fig files using GUIDE.

  0 Comments

Sign in to comment.

Accepted Answer

Adam
Adam on 14 Jun 2016
Edited: Adam on 14 Jun 2016
The problem is that what is defined in a .fig will always be a figure, not a panel that can simply be parented by your tab. A figure cannot be parented by anything.
One thing you could try (I haven't done so I'm not sure if it would work) is to launch your figure (i.e. the one that represent a single tab), making it invisible (you can set 'Visible' to 'off' in GUIDE itself.
Then, assuming everything you want within that .fig is in a panel you could try re-parenting the panel from the .fig to your uitab. This would probably involve some unpleasant use of findall or similar to fish the panel handle out of your invisible figure, but it might work.
I would suggest creating the simplest test case you can to see if this works rather than on your real code. Just create a .fig with a panel in it and some slider or whatever and then create your uitab on command line or in a script and try locating the panel handle from the launched figure and reparenting it.
Personally I tend to do programmatic UIs when I use tabs, but it is a big inconvenience (though GUIDE performance is so bad nowadays it is less of an inconvenience than it might have been!)

  1 Comment

Joakim Magnusson
Joakim Magnusson on 14 Jun 2016
Thanks! It worked.
I made a simple test case so sorry for the bad variable names, but maybe it can help someone else anyway.
%Create tab group
handles.untitled_tab = untitled_tab(handles);
set(handles.untitled_tab.uipanel1, 'Parent',handles.figure1)
handles.tgroup = uitabgroup('Parent', handles.figure1,'TabLocation', 'left');
handles.tab1 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 1');
handles.tab2 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 2');
handles.tab3 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 3');
handles.tab4 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 3');
%Place panels into each tab
set(handles.p1,'Parent',handles.tab1)
set(handles.p2,'Parent',handles.tab2)
set(handles.p3,'Parent',handles.tab3)
set(handles.untitled_tab.uipanel1,'Parent',handles.tab4)
%Reposition each panel to same location as panel 1
set(handles.p2,'position',get(handles.p1,'position'));
set(handles.p3,'position',get(handles.p1,'position'));
set(handles.untitled_tab.uipanel1,'position',get(handles.p1,'position'));
I put this code in the gui's opening function.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!