Creating Graphical User Interfaces    

Command-Line Accessibility

You can restrict access to the GUI figure handle from the command line with the Command-line accessibility options. This prevents users from inadvertently changing the appearance of the GUI by entering commands, such as plot, that alter the current figure. With the default option, which is Callback (GUI becomes Current Figure within Callbacks), the GUI can only become the MATLAB current figure, by the command gcf, while a callback is executing.

There may be occasions when you want the GUI figure handle to be accessible from the command line. For example, you might want the GUI to display plots created at the command line. In this case, you should select On (GUI may become Current Figure from Command Line).

Access Options

There are four options for Command line accessibility:

The following table summarizes how the four Command line accessibility options configure HandleVisibility and IntegerHandle in the Property Inspector (see Figure Properties That Control Access):

Option
Handle Visibility
Integer Handle
Callback
Callback
off
Off
off
off
On
on
on
Other
user specifies
user specifies

Figure Properties That Control Access

There are two figure properties that control command-line accessibility of the figure:

HandleVisibility - Callback.   Setting HandleVisibility to callback causes handles to be visible from within callback routines or functions invoked by callback routines, but not from within functions invoked from the command line. This provides a means to protect GUIs from command-line users, while allowing callback routines to have complete access to object handles. You should use this option if your GUI contains axes.

HandleVisibility - Off.   Setting the HandleVisibility property to off removes the handle of the figure from the list of root object children so it will not become the current figure (which is the target for graphics output). The handle remains valid, however, so a command that specifies the handle explicitly still works (such as close(1)). However, you cannot use commands that operate only on the current figure or axes. These commands include xlabel, ylabel, zlabel, title, gca, gcf, and findobj.

HandleVisibility - On.   Handles are always visible when HandleVisibility is on.

IntegerHandle.   Setting the IntegerHandle property to off causes MATLAB to assign nonreusable real-number handles (e.g., 67.0001221...) instead of integers. This greatly reduces the likelihood of someone accidently performing an operation on the figure.

Using findobj

When you set the Command-line accessibility to off, the handle of the GUI figure is hidden. This means you cannot use findobj to locate the handles of the uicontrols in the GUI. As an alternative, the GUI M-file creates a handle structure that contains the handles of each uicontrol in the GUI and passes this structure to subfunctions.


  Resize Behavior Generate FIG-File and M-File