How to generate 'N' number of pop-up windows in app design using MATLAB.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vaibhavi Pallavaneni
le 28 Mar 2024
Commenté : Vaibhavi Pallavaneni
le 28 Mar 2024
I'm creating an app in app designer using Matlab. in my case different Pop-up windows should be opened. For example, Number of girls = x, then x pop-up windows should be opened and inside pop-up window1,Girl1 = 'edit text value', similarly inside Pop-up window2, Girl2 = 'edit text value' and so on. In 'edit text value' i should be able to give some numeric value.
Réponse acceptée
Vandit
le 28 Mar 2024
Modifié(e) : Vandit
le 28 Mar 2024
Hello Vaishnavi,
Based on the functionality you described, you can create a customized application using "uitabgroup" and "uitab"functions to generate and manage tabs, "uieditfield"function for input fields where users can enter text, and "uilabel"function to add descriptive text labels next to the input fields.
Below is a code snippet that dynamically creates tabs based on user input:
% App initialization and component creation
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure('Position', [100 100 640 480]);
app.UIFigure.Name = 'My App';
% Create TabGroup
app.TabGroup = uitabgroup(app.UIFigure, 'Position', [20 80 600 380]);
% Create EditField
app.EditField = uieditfield(app.UIFigure, 'numeric', ...
'Position', [20 20 100 22], ...
'ValueChangedFcn', @(src, event) createTabs(app, src, event));
end
% Create tabs based on input value
function createTabs(app, src, event)
% Clear existing tabs
delete(app.TabGroup.Children);
% Get the input value from the EditField
numTabs = app.EditField.Value;
% Validate the input to be positive
if numTabs < 1
uialert(app.UIFigure, 'Please enter a positive number', 'Input Error');
return;
end
% Create the specified number of tabs
for i = 1:numTabs
% Create a new tab
tab = uitab(app.TabGroup, 'Title', ['Tab ' num2str(i)]);
% Create an edit label and edit text in the tab
editLabel = uilabel(tab, 'Text', 'Edit Label:', ...
'Position', [50, 100, 100, 22]);
editText = uieditfield(tab, 'text', 'Position', [150, 100, 100, 22]);
end
end
end
In the above code, "createTabs" is a custom function designed to dynamically generate a specified number of tabs within a tab group based on user input. Each tab created contains a 'Edit Label' and an adjacent editable text field, allowing for customized user interaction within each tab.
Below is the image of the app you received after executing the provided code snippet.
For more information about the "uitabgroup", "uitab", "uieditfield", and "uilabel" functions, please refer to the links provided below:
Hope this helps.
3 commentaires
Vandit
le 28 Mar 2024
Hello Vaishnavi,
The code snippet provided above is already creating the tabs dynamically when the input field value is changed. If it is not working as expected, please double-check the event listener setup or share more details for further assistance.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!