Generate edit text boxes by providing their numbers in GUI
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to generate n number of edit text boxes by providing n as input in GUI. Is it possible?
For example,
User first provide value of n. Let it be 5
Then 5 edit boxes will be generated and then user provide values in them.
1 Commento
Rik
il 31 Gen 2020
This is fairly easy with a programmatic GUI, as you can create the uicontrol objects in a loop and determine the Position based on the number of inputs.
Risposte (1)
Kanishk
il 23 Dic 2024
Modificato: Kanishk
il 23 Dic 2024
Following Rik's comment, here is a simple function using loops to generate edit field.
function generateDynamicEditFields()
fig = uifigure('Name', 'Dynamic Edit Fields');
numField = uieditfield(fig, 'numeric', 'Position', [180 250 100 22]);
generateButton = uibutton(fig, 'push', 'Text', 'Generate', ...
'Position', [300 250 70 22], ...
'ButtonPushedFcn', @(btn, event) generateEditFields(fig, numField.Value));
end
function generateEditFields(parentFig, n)
delete(findall(parentFig, 'Type', 'uieditfield'));
for i = 1:n
uieditfield(parentFig, 'text', ...
'Position', [20, 250 - i*30, 350, 22]);
end
end
To add, you can use 'delete' and 'findall' to remove previously generated Edit fields.
delete(findall(parentFig, 'Type', 'uieditfield'));
Executing the 'generateDynamicEditFields' generates the follwing figure.
generateDynamicEditFields
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1821672/image.png)
You can learn more about 'uieditfield', 'delete' and 'findall' from the following commands.
web(fullfile(docroot, 'matlab/ref/uieditfield.html'))
web(fullfile(docroot, 'matlab/ref/delete.html'))
web(fullfile(docroot, 'matlab/ref/findall.html'))
Hope that helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!