GUIDE Options

The GUI Options Dialog Box

You can use the GUI Options dialog box to configure various behaviors that are specific to the GUIDE GUI you are creating. These options take effect when you next save the GUI.

Access the dialog box from the GUIDE Layout Editor by selecting Tools > GUI Options.

Resize Behavior

You can control whether users can resize the figure window containing your GUI and how MATLAB® handles resizing. GUIDE provides three options:

  • Non-resizable — Users cannot change the window size (default).

  • Proportional — The software automatically rescales the components in the GUI in proportion to the new figure window size.

  • Other (Use SizeChangedFcn) — Program the GUI to behave in a certain way when users resize the figure window.

The first two options set figure and component properties appropriately and require no other action. Other (Use SizeChangedFcn) requires you to write a callback routine that recalculates sizes and positions of the components based on the new figure size. For a discussion and examples of using a SizeChangedFcn, see the GUIDE examples Panel and GUI For Managing Persistent Data.

Command-Line Accessibility

You can restrict access to a GUI figure from the command line or from a code file with the GUIDE Command-line accessibility options.

Unless you explicitly specify a figure handle, many commands, such as plot, alter the current figure (the figure specified by the root CurrentFigure property and returned by the gcf command). The current figure is usually the figure that is most recently created, drawn into, or mouse-clicked. You can programmatically designate a figure h (where h is its handle) as the current figure in four ways:

  1. set(groot,'CurrentFigure',h) — Makes figure h current, but does not change its visibility or stacking with respect to other figures

  2. figure(h) — Makes figure h current, visible, and displayed on top of other figures

  3. axes(h) — Makes existing axes h the current axes and displays the figure containing it on top of other figures

  4. plot(h,...), or any plotting function that takes an axes as its first argument, also makes existing axes h the current axes and displays the figure containing it on top of other figures

The gcf function returns the handle of the current figure.

h = gcf

For a GUI created in GUIDE, set the Command-line accessibility option to prevent users from inadvertently changing the appearance or content of a GUI by executing commands at the command line or from a script or function, such as plot. The following table briefly describes the four options for Command-line accessibility.

Option

Description

Callback (GUI becomes Current Figure within Callbacks)

The GUI can be accessed only from within a GUI callback. The GUI cannot be accessed from the command line or from a script. This is the default.

Off (GUI never becomes Current Figure)

The GUI can not be accessed from a callback, the command line, or a script, without the handle.

On (GUI may become Current Figure from Command Line)

The GUI can be accessed from a callback, from the command line, and from a script.

Other (Use settings from Property Inspector)

You control accessibility by setting the HandleVisibility and IntegerHandle properties from the Property Inspector.

Generate FIG-File and MATLAB File

Select Generate FIG-file and MATLAB file in the GUI Options dialog box if you want GUIDE to create both the FIG-file and the GUI code file (this is the default). Once you have selected this option, you can select any of the following items in the frame to configure GUI code:

See Files Generated by GUIDE for information about these files.

Generate Callback Function Prototypes

If you select Generate callback function prototypes in the GUI Options dialog, GUIDE adds templates for the most commonly used callbacks to the GUI code for most components you add to the GUI. You must then write the code for these callbacks.

GUIDE also adds a callback whenever you edit a callback routine from the Layout Editor's right-click context menu and when you add menus to the GUI using the Menu Editor.

See Write Callbacks Using the GUIDE Workflow for general information about callbacks.

    Note   This option is available only if you first select the Generate FIG-file and MATLAB file option.

GUI Allows Only One Instance to Run (Singleton)

This option allows you to select between two behaviors for the GUI figure:

  • Allow MATLAB software to display only one instance of the GUI at a time.

  • Allow MATLAB software to display multiple instances of the GUI.

If you allow only one instance, the software reuses the existing GUI figure whenever the command to run the GUI is issued. If a GUI already exists, the software brings it to the foreground rather than creating a new figure.

If you clear this option, the software creates a new GUI figure whenever you issue the command to run the GUI.

Even if you allow only one instance of a GUI to run at once, initialization can take place each time you invoke it from the command line. For example, the code in an OpeningFcn will run each time a GUIDE GUI runs unless you take steps to prevent it from doing so. Adding a flag to the handles structure is one way to control such behavior. You can do this in the OpeningFcn, which can run initialization code if this flag doesn't yet exist and skip that code if it does.

    Note   This option is available only if you first select the Generate FIG-file and MATLAB file option.

Use System Color Scheme for Background

The default color used for GUI components is system dependent. This option enables you to make the figure background color the same as the default component background color.

To ensure that the figure background matches the color of the components, select Use system color scheme for background in the GUI Options dialog.

    Note   This option is available only if you first select the Generate FIG-file and MATLAB file option.

Generate FIG-File Only

The Generate FIG-file only option enables you to open figures and GUIs to perform limited editing. These can be any figures and need not be GUIs. GUIs need not have been generated using GUIDE. This mode provides limited editing capability and may be useful for GUIs generated in MATLAB Versions 5.3 and earlier. See the guide function for more information.

GUIDE selects Generate FIG-file only as the default if you do one of the following:

  • Start GUIDE from the command line by providing one or more figure handles as arguments.

    guide(fh)

    In this case, GUIDE selects Generate FIG-file only, even when a code file with a corresponding name exists in the same folder.

  • Start GUIDE from the command line and provide the name of a FIG-file for which no code file with the same name exists in the same folder.

    guide('myfig.fig')
  • Use the GUIDE Open Existing GUI tab to open a FIG-file for which no code file with the same name exists in the same folder.

When you save the figure or GUI with Generate FIG-file only selected, GUIDE saves only the FIG-file. You must update any corresponding code files yourself, as appropriate.

If you want GUIDE to manage the GUI code file for you, change the selection to Generate FIG-file and MATLAB file before saving the GUI. If there is no corresponding code file in the same location, GUIDE creates one. If a code file with the same name as the original figure or GUI exists in the same folder, GUIDE overwrites it. To prevent overwriting an existing file, save the GUI using Save As from the File menu. Select another file name for the two files. GUIDE updates variable names in the new code file as appropriate.

Callbacks for GUIs without Code

Even when there is no code file associated with a GUI FIG-file, you can still provide callbacks for GUI components to make them perform actions when used. In the Property Inspector, you can type callbacks in the form of strings, built-in functions, or MATLAB code file names; when the GUI runs, it will execute them if possible. If the callback is a file name, it can include arguments to that function. For example, setting the Callback property of a push button to sqrt(2) causes the result of the expression to display in the Command Window:

ans =
    1.4142

Any file that a callback executes must be in the current folder or on the MATLAB path. For more information on how callbacks work, see Write Callbacks Using the GUIDE Workflow

Was this topic helpful?