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

4 visualizaciones (últimos 30 días)
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...

Respuesta aceptada

Jan
Jan el 11 de Feb. de 2017
Editada: Jan el 11 de Feb. de 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 comentario
Yoav Romach
Yoav Romach el 11 de Feb. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by