How to create a number of "Edit Text" feilds in a GUI, depending on the user input given in the GUI through an "Edit text" field itself?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to create a GUI in which there is a single Editable text field and a Push button. Depending upon the input number i give in the text field i need that many number of new Editable text fields created in the GUI. For example, inside the text field if i give input number as 5 and I push the button, i need 5 new editable text fields to be created.Is it possible to be done using uicontrols?
0 Kommentare
Antworten (2)
Grzegorz Knor
am 2 Sep. 2011
Yes, it is possible :) Look at the example:
function test
e = uicontrol('Style','Edit','Units','Normalized','Position',[.4 .5 .2 .1]);
uicontrol('Style','PushButton','Units','Normalized',...
'Position',[.4 .3 .2 .1],'String','Create','Callback',@b_clbck);
function b_clbck(src,evnt)
n = str2double(get(e,'String'));
create_figure(n)
end
function create_figure(n)
figure('Units','Normalize','Name','New Figure')
for k=1:n
uicontrol('Style','Edit','Units','Normalized',...
'Position',[.4 k/n-.75/n .2 .75/n],'String',num2str(k));
end
end
end
0 Kommentare
Paulo Silva
am 2 Sep. 2011
function testui
hp = uicontrol('Style', 'pushbutton', 'String', 'do it',...
'Position', [1 150 60 60], 'Callback', @doit);
he = uicontrol('Style', 'edit', 'String', '',...
'Position', [61 150 60 60]);
function doit(obj,ev)
n=str2num(get(he,'string'));
for m=1:n
hea(m)=uicontrol('Style', 'edit', 'String', '',...
'Position', [60*m-59 80 60 60]);
end
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu String Parsing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!