How to create a dynamic number of aligned checkboxes and edit textboxes and how to tag them? Order of input arguments in uicontrol?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
John
el 23 de Sept. de 2015
Comentada: Walter Roberson
el 28 de Dic. de 2017
Hey Guys,
i have to create a GUI that adapts to the users input! So if the user puts is a 5, i would like to have five aligned checkboxes and edit textboxes. The names of the static textboxes as well as the Tags of the checkboxes shall be dependent of the input number given by the user. And i woould like to pack it into a panel.
I created this code:
stages = 5;
fig = figure('Visible','off');
box = zeros(stages,1);
txtbox = zeros(stages,1);
panel = uipanel('parent',fig,...
'Title','Choose stages to plot',...
'position',[.01 .05 .25 .95]);
A=zeros(stages,1);
for i = 1:stages
box(i,1) = uicontrol('parent',panel,'style','checkbox',...
'string',i,...
'position',[20 360-i*25 40 20],...
'callback','A(i,1)=1');
txtbox = uicontrol(fig,'Style','text',...
'String','Select ',...
'Position',[100 360-i*25 40 20]);
end
set(fig,'Visible','on')
Some questions to it.
1) How can i put the static text into the panel and align it with the checkboxes? i cannot find the order of input arguments for uicontrol so i dont know where to put 'parent' and panel as arguments.
2) How can i tag the checkboxes according to the number...so first checkbox shall have the tag 'checkbox1', the second 'checkbox2' and so on....
3) Is it possible to make the GUI window adapt to the number of created checkboxes so that it resizes in order to make all checkboxes visible or that the user is able to scroll down?
I know those are many questions:( i would be very glad to get answers!
Best regards, John
0 comentarios
Respuesta aceptada
Jan
el 23 de Sept. de 2015
Question 1: put the static text into the panel
txtbox = uicontrol('parent', panel, ...
instead of txtbox = uicontrol(fig, ...
Question 2: dynamic tag
box(i) = uicontrol('parent', panel,'style','checkbox', ...
'tag', sprintf('checkbox%d', i), ...
Note: Be careful with tags. It might be easier to store a list of the handles in a variable and share it with the callbacks. See setappdata and guidata.
Question 3: Adjust the figure size.
The figure size can be easiliy adjusted by adjustig the figure size. Compute the required height of the figure and simply set it initally or finally:
set(fig, 'Visible', 'on', 'Position', [100, 100, computedHeight, Width]);
9 comentarios
Ahmed Khalil
el 28 de Dic. de 2017
I'm so sorry to be a bother. I added setappdata(panel, 'box', box) but it gives this error:
Error using box Too many output arguments.
Error in multidesign2>edit1_Callback (line 101) design = uicontrol('parent',panel,'Style','edit',...
Walter Roberson
el 28 de Dic. de 2017
You would only get that error if your code assigning to box(i) had not executed in that workspace.
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!