How to generate 'N' number of pop-up windows in app design using MATLAB.

11 views (last 30 days)
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.

Accepted Answer

Vandit
Vandit on 28 Mar 2024 at 6:21
Edited: Vandit on 28 Mar 2024 at 6:22
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 Comments
Vandit
Vandit on 28 Mar 2024 at 10:54
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.
Virajita Parameswaran
Virajita Parameswaran on 28 Mar 2024 at 11:10
I do some changes. It's working now. Thank u so much for your help Vandit.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!