AppDesigner / GUIDE: generate unknown number of new GUI elements as a function

1 view (last 30 days)
Dear experts,
is there a way for the user to create new gui-elements, while the developed application is actually running?
For example:
  • The application shows an Import button
  • each time the user presses the import button, a new set of gui elements is created and their callback functions can be executed
Background:
I have an application (created with GUIDE and later compiled) that handles sensor data. The user sometimes only has 1 sensor but sometimes more sensors to analyze (e.g. up to 16). For each sensor, it requires a set of gui elements (and callback functions) that manages/displays sensor properties.
Currrently I need to provide all 16 sets of gui elements in order to support 16 sensors... if i want to support 20 sensors i would need to create new sets of gui elements and fill their callback functions with life.
My question is if I can automatically create the set of gui elements
  • editbox_1
  • popupmenu_1
  • checkbox_1
and then another set
  • editbox_2
  • popupmenu_2
  • checkbox_2
up to set
  • editbox_x
  • popupmenu_x
  • checkbox_x
and assign a function to the accoring callback function. such as
  • editbox_x_callback (that always calls the function "editbox_function"), where x could be any number
function editbox_x_callback(hObject, eventdata, handles)
editbox_function()
end

Accepted Answer

Adam Danz
Adam Danz on 9 Nov 2022
Edited: Adam Danz on 10 Nov 2022
Your quesiton specifies AppDesigner and GUIDE but don't use GUIDE since it will be removed in a future release.
Yes, you can programmatically add components to your app in AppDesigner.
App Components have their own functions that you can use to add them to a figure. Example: uicheckbox; Check out the Component Library for reference to other ui components.
Some considerations
  • Parent: you'll need to assign the app's figure or a uipanel or uitab in your app as the parent of the component
  • Position: You'll need to set the component's position within the app - this is the main benefit of designing the layout within AppDesigner rather than doing so programmatically. Consider using a Grid Layout Manager.
  • Property management: You'll need to store the handle to the added components somehwere within the app so the handles are accessible within the app.
But it's not necessarily the best idea
Dynamic components may lead to inconsistencies to the user experience of your app. How did I enter this data last time, where did that component go? It may be difficult for you, as an analyst, to understand where the user's data came from.
An alternative would be to set up a tab group or a set of uipanels that contain all of the possible components but control their enable-state of visible-state as needed. This way, all components already exist, they are positioned within App Designer, and you'll avoid the snags listed in the bullet points above.
  1 Comment
Marten Amschler
Marten Amschler on 10 Nov 2022
Thanks for your detailed answer and the link, as well as the "user experience" remark!
I will definetly take everyting into consideration when I migrate to AppDesigner.
BR, Marten

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by