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

조회 수: 15 (최근 30일)
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
Walter Roberson
Walter Roberson 2021년 5월 11일
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 2021년 5월 11일
@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 :)

댓글을 달려면 로그인하십시오.

채택된 답변

Jadon Latta
Jadon Latta 2021년 5월 11일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by