Create a UI Component when Checkbox is checked, remove when unchecked

15 views (last 30 days)
Hello,
I am trying to create a GUI in the App Designer and I want to have it so that when the user presses the checkbox component a new listbox component will be created on screen with further options for the user to interact with. If the user were to uncheck the box I would have the UI created disappear. I have tried to no avail and have not been able to find anything else online helping with this.
Any help is much appreciated!
  2 Comments
Walter Roberson
Walter Roberson on 11 May 2021
Is it necessary to create it dynamically? Or would it be acceptable to instead create it statically and only make it visible when it is needed?
Jadon Latta
Jadon Latta on 11 May 2021
@Walter Roberson I was actually just about to come and delete the post because I found the visible/invisible attributes and then rewrote what I had to implement that instead and that is working great. Thank you so much for the help though :)

Sign in to comment.

Accepted Answer

Jadon Latta
Jadon Latta on 11 May 2021
Creating dynamically isn't necessary in my situation and this can instead be solved by simply toggling the visibility of the components. By unchecking the visibilty option within the component attributes and then implementing this code block
% Value changed function: ExtraMilestoneRequirementsCheckBox
function ExtraMilestoneBoxChecked(app, event)
value = app.ExtraMilestoneRequirementsCheckBox.Value;
if value == 1
app.PhasesWithMilestoneRequirementsLabel.Visible = 'on';
app.PhasesWithMilestoneRequirementsListBox.Visible = 'on';
end
if value == 0
app.PhasesWithMilestoneRequirementsLabel.Visible = 'off';
app.PhasesWithMilestoneRequirementsListBox.Visible = 'off';
end
end
into the callback for my checkbox I was able to have the listbox toggle visibility based on the button results.
I will leave the OP up with this answer to help anyone in the future who attempts to follow the same logic as I did and ends up googling how to create a GUI component on button press haha.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer 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!