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

4 vues (au cours des 30 derniers jours)
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...

Réponse acceptée

Jan
Jan le 11 Fév 2017
Modifié(e) : Jan le 11 Fév 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 commentaire
Yoav Romach
Yoav Romach le 11 Fév 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!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by