Azzera filtri
Azzera filtri

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

3 visualizzazioni (ultimi 30 giorni)
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...

Risposta accettata

Jan
Jan il 11 Feb 2017
Modificato: Jan il 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 Commento
Yoav Romach
Yoav Romach il 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by