Specifications
4 Programming GUIs
4-38
Controlling Figure Window Behavior
When designing a GUI you need to consider how you want the figure window
to behave. The appropriate behavior for a particular GUI depends on intended
use. Consider the following examples:
• A GUI that implements tools for annotating graphs is usually designed to be
available while the user performs other MATLAB tasks. Perhaps this tool
operates on only one figure at a time so you need a new instance of this tool
for each graph.
• A dialog that requires an answer to a question may need to block MATLAB
execution until the user answers the question. However, the user may need
to look at other MATLAB windows to obtain information needed to answer
the question. The dialog is blocking.
• A dialog that warns users that the specified operation will delete files so you
want to force the user to respond to the warning before performing any other
action. In this case, the dialog is both blocking and modal.
The following techniques are useful for handling these GUI design issues:
• Allow single or multiple instances of the GUI at any one time.
• Use modal figure windows that allow users to interact only with the GUI.
Using Modal Figure Windows
Modal windows trap all keyboard and mouse events that occur in any visible
MATLAB window. This means a modal GUI figure can process the user
interactions with any of its components, but does not allow the user to access
any other MATLAB window (including the command window). In addition, a
modal window remains stacked on top of other MATLAB windows until it is
deleted, at which time focus returns to the window that last had focus. See the
figure
WindowStyle property for more details.
Use modal figures when you want to force users to respond to your GUI before
allowing them to take other actions in MATLAB.
Making a Figure Modal
Set the figure’s WindowStyle property to modal to make the window modal. You
can use the Property Inspector to change this property or add a statement in