Setting proprties for multiple UIControl objects at once (or setting a default)

4 Ansichten (letzte 30 Tage)
Hey, I'm creating a complex GUI that will have many similar objects (for example, text). I want all of them to have the same properties, besides the text, for example:
scanParametersFromLabel = uicontrol('Parent', scanParameters, ...
'Style', 'text', 'String', 'From', 'FontSize', fontSize, 'ForegroundColor', [0.5 0.5 0.5]);
scanParametersToLabel = uicontrol('Parent', scanParameters, ...
'Style', 'text', 'String', 'To', 'FontSize', fontSize, 'ForegroundColor', [0.5 0.5 0.5]);
scanParametersNPointsLabel = uicontrol('Parent', scanParameters, ...
'Style', 'text', 'String', '# Points', 'FontSize', fontSize, 'ForegroundColor', [0.5 0.5 0.5]);
scanParametersFixLabel = uicontrol('Parent', scanParameters, ...
'Style', 'text', 'String', 'Fix', 'FontSize', fontSize, 'ForegroundColor', [0.5 0.5 0.5]);
scanParametersPositionLabel = uicontrol('Parent', scanParameters, ...
'Style', 'text', 'String', 'Position', 'FontSize', fontSize, 'ForegroundColor', [0.5 0.5 0.5]);
Is there anyway to quickly set all of the parameters for all objects? or maybe set a default value? It'll remove a lot of clutter from my code... For example something like this would be great:
textProprties = sprintf('''Style'', ''text'', ''String'', ''From'', ''FontSize'', fontSize, ''ForegroundColor'', [0.5 0.5 0.5]');
scanParametersFromLabel = uicontrol('Parent', scanParameters, 'String', 'From', textProprties);
I know I can do it with eval(sprintf(...)), but I was hoping for something more elegant...

Akzeptierte Antwort

Jan
Jan am 11 Feb. 2017
Bearbeitet: Jan am 11 Feb. 2017
scanParameters = figure;
fontSize = 12,
props = {'Parent', scanParameters, ...
'Style', 'text', 'FontSize', fontSize, 'ForegroundColor', [0.5 0.5 0.5]};
uicontrol('String', 'From', props{:});
I'd prefer this for clarity:
scanParameters = figure;
Props.Parent = scanParameters;
Props.FontSize = 12;
Props.Style = 'text';
Props.ForegroundColor = [0.5 0.5 0.5];
uicontrol('String', 'From', Props);
  1 Kommentar
Yoav Romach
Yoav Romach am 11 Feb. 2017
Amazing, all I needed to do was to put it in a Cell... I even thought about doing it, didn't know why I didn't try :\
Thanks a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by