Thursday, June 22, 2017

[Matlab GUI] Create the tab UI using uitabgroup and uitab in GUIDE

This code was tested on Matlab R2014b. I am not sure if it works in Matlab R2014a or earlier version.
Matlab R2014b and later version now support the commands for tab creation, i.e. can create tabs programmatically but not support yet for GUIDE.
So need some workaround for creating tabs in GUIDE.
Below is one of workaround for tab in GUIDE

1. OpeningFcn

handles = TabCreation(handles);

2. User-define function

% Create each tab into uitabgroup
function handles = TabCreation(handles)
% Prevent an annoying warning message
warning off MATLAB:uitabgroup:OldVersion

%---- Create a tab group
handles.tgroup = uitabgroup('Parent',handles.mainGui,'TabLocation','top');
% Set position [left, bottom, width, height], normalized unit
set(handles.tgroup,'Units','Normalized','Position',[0 0 1 0.945]);
% Create each tab
handles.maintab = uitab('Parent',handles.tgroup,'Title','Main');
handles.doetab = uitab('Parent',handles.tgroup,'Title','DoE (Automation)');
handles.simulinktab = uitab('Parent',handles.tgroup,'Title','Simulink');
% Place panels into each tab
set(handles.Tab1,'Parent',handles.maintab);
set(handles.Tab2,'Parent',handles.doetab);
set(handles.Tab3,'Parent',handles.simulinktab);

% Reposition each panel to the same location as Tab1
set(handles.Tab2,'Position',get(handles.Tab1,'Position'));
set(handles.Tab3,'Position',get(handles.Tab1,'Position'));

Related post
http://simulation4vehicle.blogspot.jp/2017/06/matlab-gui-create-tabs-using-uitabgroup.html


No comments:

Post a Comment