1+ classdef TableDemo < matlab .apps .AppBase
2+
3+ % Properties that correspond to app components
4+ properties (Access = public )
5+ UIFigure matlab.ui.Figure
6+ UITable matlab.ui.control.Table
7+ Button matlab.ui.control.Button
8+ end
9+
10+ methods (Access = private )
11+
12+ % Button pushed function: Button
13+ function ButtonPushed(app , ~)
14+ % Return all registered widgets:
15+ [~ ,w ] = mlapptools .getWidgetList(app .UIFigure );
16+ % Filter list:
17+ w = w(~cellfun(@isempty ,w .id ) & ...
18+ cellfun(@(x )~isempty(strfind(x ,' uniq' )),w .id ),: ); % #ok<STREMP>
19+ % Apply random styles:
20+ for ind1 = 1 : 4 : size(w ,1 )
21+ mlapptools .setStyle(...
22+ app .UIFigure ,...
23+ ' border' ,...
24+ ' 2px solid red' ,...
25+ w{ind1 ,' id' }{1 });
26+ end
27+
28+ for ind2 = 2 : 4 : size(w ,1 )
29+ mlapptools .setStyle(...
30+ app .UIFigure ,...
31+ ' background-image' ,...
32+ ' url(http://lorempixel.com/40/120/)' ,...
33+ w{ind2 ,' id' }{1 });
34+ end
35+
36+ for ind3 = 3 : 4 : size(w ,1 )
37+ mlapptools .setStyle(...
38+ app .UIFigure ,...
39+ ' background-color' ,...
40+ [' rgb(' num2str(randi(255 )) ' ,' num2str(randi(255 )) ' ,' ...
41+ num2str(randi(255 )) +' )' ],...
42+ w{ind3 ,' id' }{1 });
43+ end
44+
45+ for ind4 = 4 : 4 : size(w ,1 )
46+ mlapptools .setStyle(...
47+ app .UIFigure ,...
48+ ' padding' ,...
49+ ' 0cm 1cm 0cm 0cm' ,...
50+ w{ind4 ,' id' }{1 });
51+ end
52+
53+ end
54+ end
55+
56+ % App initialization and construction
57+ methods (Access = private )
58+
59+ % Create UIFigure and components
60+ function createComponents(app )
61+
62+ % Create UIFigure
63+ app.UIFigure = uifigure ;
64+ app.UIFigure.Position = [600 600 300 150 ];
65+ app.UIFigure.Name = ' UI Figure' ;
66+ setAutoResize(app , app .UIFigure , true )
67+
68+ % Create UITable
69+ app.UITable = uitable(app .UIFigure );
70+ app.UITable.ColumnName = {' Column 1' ; ' Column 2' ; ' Column 3' };
71+ app.UITable.Data = rand(3 );
72+ app.UITable.RowName = {};
73+ app.UITable.Position = [25 40 250 100 ];
74+
75+ % Create Button
76+ app.Button = uibutton(app .UIFigure , ' push' );
77+ app.Button.ButtonPushedFcn = createCallbackFcn(app , @ButtonPushed , true );
78+ app.Button.Position = [90 10 120 25 ];
79+ app.Button.Text = ' Modify!' ;
80+ end
81+ end
82+
83+ methods (Access = public )
84+
85+ % Construct app
86+ function app = TableDemo()
87+
88+ % Create and configure components
89+ createComponents(app )
90+
91+ % Register the app with App Designer
92+ registerApp(app , app .UIFigure )
93+
94+ if nargout == 0
95+ clear app
96+ end
97+ end
98+
99+ % Code that executes before app deletion
100+ function delete(app )
101+
102+ % Delete UIFigure when app is deleted
103+ delete(app .UIFigure )
104+ end
105+ end
106+ end
0 commit comments