source: MML/trunk/machine/SOLEIL/common/toolbox/GUILayout/layoutHelp/Examples/tabpanelexample.m @ 17

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 2.1 KB
Line 
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
8window = 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.
17hbox = uiextras.HBoxFlex('Parent', window, 'Spacing', 3);
18panel = uiextras.Panel( ...
19    'Parent', hbox, ...
20    'Padding', 5, ...
21    'Title', 'Left' );
22tabpanel = 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.
29panellist = uicontrol( 'Style', 'list', ...
30    'Parent', panel, ...
31    'String', {'1', '2', '3'}, ...
32    'BackgroundColor', 'w', ...
33    'Callback', @(a,b) set( tabpanel, 'SelectedChild', get( a, 'Value' ) ) );
34set( 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
38htab1 = uiextras.Panel( 'Parent', tabpanel, 'Padding', 5, 'Title', '1');
39uicontrol( 'Style', 'listbox', 'Parent', htab1, ...
40    'String', {'1', '1', '1'}, ...
41    'BackgroundColor', 'w' );
42
43htab2 = uiextras.Panel( 'Parent', tabpanel, 'Padding', 5, 'Title', '2');
44uicontrol( 'Style', 'listbox', 'Parent', htab2, ...
45    'String', {'2', '2', '2'}, ...
46    'BackgroundColor', 'w' );
47
48htab3 = uiextras.Panel( 'Parent', tabpanel, 'Padding', 5, 'Title', '3');
49uicontrol( 'Style', 'listbox', 'Parent', htab3, ...
50    'String', {'3', '3', '3'}, ...
51    'BackgroundColor', 'w' );
52
53%% Update the tab titles
54tabpanel.TabNames = {'1', '2', '3'};
55
56%% Show the first tab
57tabpanel.SelectedChild = 1;
Note: See TracBrowser for help on using the repository browser.