1 | %% A TabPanel Example
|
---|
2 | % This example shows how to use tabs within a layout. It also shows how to
|
---|
3 | % use the TabPanel Callback property to update other GUI elements when the
|
---|
4 | % visible tab is changed.
|
---|
5 |
|
---|
6 | %% Open the window
|
---|
7 | % Open a new figure window and remove the toolbar and menus
|
---|
8 | window = figure( 'Name', 'A TabPanel example', ...
|
---|
9 | 'MenuBar', 'none', ...
|
---|
10 | 'Toolbar', 'none', ...
|
---|
11 | 'NumberTitle', 'off' );
|
---|
12 |
|
---|
13 | %% Create the layout
|
---|
14 | % The layout involves two panels side by side. This is done using a
|
---|
15 | % flexible horizontal box. The left-hand side is filled with a standard
|
---|
16 | % panel and the right-hand side with some tabs.
|
---|
17 | hbox = uiextras.HBoxFlex('Parent', window, 'Spacing', 3);
|
---|
18 | panel = uiextras.Panel( ...
|
---|
19 | 'Parent', hbox, ...
|
---|
20 | 'Padding', 5, ...
|
---|
21 | 'Title', 'Left' );
|
---|
22 | tabpanel = uiextras.TabPanel( 'Parent', ...
|
---|
23 | hbox, ...
|
---|
24 | 'Padding', 0);
|
---|
25 |
|
---|
26 | %% Add a list on the left
|
---|
27 | % Note that we link the callbacks from the list to the tab selection and
|
---|
28 | % the tab callback to the list such that they are kept in sync.
|
---|
29 | panellist = uicontrol( 'Style', 'list', ...
|
---|
30 | 'Parent', panel, ...
|
---|
31 | 'String', {'1', '2', '3'}, ...
|
---|
32 | 'BackgroundColor', 'w', ...
|
---|
33 | 'Callback', @(a,b) set( tabpanel, 'SelectedChild', get( a, 'Value' ) ) );
|
---|
34 | set( tabpanel, 'Callback', @(a,b) set( panellist, 'Value', b.SelectedChild ) );
|
---|
35 |
|
---|
36 | %% Create some contents
|
---|
37 | % Each tab is filled with a list box showing some numbers
|
---|
38 | htab1 = uiextras.Panel( 'Parent', tabpanel, 'Padding', 5, 'Title', '1');
|
---|
39 | uicontrol( 'Style', 'listbox', 'Parent', htab1, ...
|
---|
40 | 'String', {'1', '1', '1'}, ...
|
---|
41 | 'BackgroundColor', 'w' );
|
---|
42 |
|
---|
43 | htab2 = uiextras.Panel( 'Parent', tabpanel, 'Padding', 5, 'Title', '2');
|
---|
44 | uicontrol( 'Style', 'listbox', 'Parent', htab2, ...
|
---|
45 | 'String', {'2', '2', '2'}, ...
|
---|
46 | 'BackgroundColor', 'w' );
|
---|
47 |
|
---|
48 | htab3 = uiextras.Panel( 'Parent', tabpanel, 'Padding', 5, 'Title', '3');
|
---|
49 | uicontrol( 'Style', 'listbox', 'Parent', htab3, ...
|
---|
50 | 'String', {'3', '3', '3'}, ...
|
---|
51 | 'BackgroundColor', 'w' );
|
---|
52 |
|
---|
53 | %% Update the tab titles
|
---|
54 | tabpanel.TabNames = {'1', '2', '3'};
|
---|
55 |
|
---|
56 | %% Show the first tab
|
---|
57 | tabpanel.SelectedChild = 1; |
---|