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?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Grzegorz Knor
2011-9-2
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 个评论
Paulo Silva
2011-9-2
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!