MATLAB Creating Graphical User Interfaces

(Barry) #1

14 Examples of UIs Created Programmatically


lmnew then calls the enable_updown function. The enable_updown function sets the
Enable property of the pair of push buttons that migrate items higher or lower in the
list box. It disables the Move Up button when the selected item is at the top of the list. It
also disables the Move Down button when the selected item is at the bottom of the list.
Then, the enable_updown function copies the current list selection into the edit text
box. Finally, it sets the “dirty” flag in the figure's application data to indicate that the
UI's data or state has changed.

Having set up the UI to receive data, the lmnew function enables the File > Import list
menu option and its submenu

List Master Menu Callbacks

List Master has seven menu items and three submenu items. To obtain user input, the
menu callbacks call these MATLAB functions:


  • errordlg (Open, Export list to workspace, Export list to file)

  • inputdlg (New, Export list to workspace)

  • listdlg (Import list)

  • questdlg (Export list to workspace, Quit)

  • uigetfile (Open)

  • uiputfile (Export list to file, Save as)


The New menu item has two modes of operation, depending on whether the UI is blank
or already contains a list box and controls. The lmnew callback determines the state of
the UI by examining the figure's Name property:


  • If the UI is blank, the name is “ListMaster”.

  • If the UI contains a list, the name is “Listmaster-” followed by a list name.


Called from a blank UI, the function requests a name, and then populates the figure with
all controls. Called from a UI that contains a list, lmnew calls the main listmaster
function to create a new UI, and uses that figure's handle (instead of its own) when
populating it with controls.
Free download pdf