Control UI figure appearance and behavior for uifigure-based apps (2024)

Table of Contents
Window Appearance Color — Background color RGB triplet | hexadecimal color code | 'r' | 'g' | 'b' | ... WindowStyle — Window style 'normal' (default) | 'modal' | 'alwaysontop' WindowState — Window state 'normal' (default) | 'minimized' | 'maximized' | 'fullscreen' Position and Size Units — Units of measurement 'pixels' (default) | 'normalized' | 'inches' | 'centimeters' | 'points' | 'characters' InnerPosition — Location and size of UI figure, excluding borders and title bar [left bottom width height] Resize — Resizable 'on' (default) | on/off logical value Plotting Colormap — Color map for UIAxes content parula (default) | m-by-3 array of RGB triplets Alphamap — Transparency map for axes content vector of 64 values between 0 and 1 (default) | vector of values between 0 and 1 Mouse Pointer Pointer — Pointer symbol 'arrow' (default) | 'ibeam' | 'crosshair' | 'watch' | 'topl' | 'custom' | ... PointerShapeCData — Custom pointer symbol 16-by-16 matrix (default) | 32-by-32 matrix PointerShapeHotSpot — Active pixel of pointer [1 1] (default) | two-element vector Interactivity Visible — State of visibility'on' (default) | on/off logical value CurrentAxes — Target axes in current UI figure UIAxes object | Axes object | PolarAxes object | graphics object CurrentObject — Current object empty GraphicsPlaceholder array (default) | child object of UI figure CurrentPoint — Current point two-element vector CurrentCharacter — Current character '' (default) | character SelectionType — Mouse selection type 'normal' (default) | 'extend' | 'alt' | 'open' ContextMenu — Context menu empty GraphicsPlaceholder array (default) | ContextMenu object Common Callbacks ButtonDownFcn — Button down callback '' (default) | function handle | cell array | character vector Keyboard Callbacks KeyPressFcn — Key-press callback '' (default) | function handle | cell array | character vector KeyReleaseFcn — Key-release callback '' (default) | function handle | cell array | character vector Window Callbacks CloseRequestFcn — Close request callback 'closereq' (default) | function handle | cell array | character vector WindowButtonDownFcn — Window button down callback '' (default) | function handle | cell array | character vector WindowButtonMotionFcn — Window button motion callback '' (default) | function handle | cell array | character vector WindowButtonUpFcn — Window button up callback '' (default) | function handle | cell array | character vector WindowKeyPressFcn — Window key-press callback '' (default) | function handle | cell array | character vector WindowKeyReleaseFcn — Window key-release callback '' (default) | function handle | cell array | character vector WindowScrollWheelFcn — Window scroll wheel callback '' (default) | function handle | cell array | character vector Callback Execution Control Parent/Children Parent — Parent object root object Children — Children of Figure object empty GraphicsPlaceholder array (default) | 1-D array of component objects HandleVisibility — Visibility of object handle 'off' (default) | 'callback' | 'on' Identifiers Icon — Icon source or file '' (default) | character vector | string scalar | m-by-n-by-3 truecolor image array Number — Number integer | [] NumberTitle — Use number title 'off' (default) | on/off logical value IntegerHandle — Use integer handle 'off' (default) | on/off logical value Type — Type of graphics object 'figure' Version History R2021a: Create UI figures that remain in the foreground R2020b: Create modal UI figures R2020b: Specify custom icons See Also Topics MATLAB Command Americas Europe Asia Pacific References

Control UI figure appearance and behavior for uifigure-based apps

expand all in page

UI figures are containers for creating apps in App Designer or programmatically with the uifigure function. Properties control the appearance and behavior of the UI figure. Use dot notation to refer to a particular object and property:

fig = uifigure;fig.Name = 'My App'; 

Window Appearance

expand all

Background color, specified as an RGB triplet, a hexadecimal color code, or one of the color options listed in the table.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1], for example, [0.4 0.6 0.7].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
"red""r"[1 0 0]"#FF0000"

Control UI figure appearance and behavior for uifigure-basedapps (1)

"green""g"[0 1 0]"#00FF00"

Control UI figure appearance and behavior for uifigure-basedapps (2)

"blue""b"[0 0 1]"#0000FF"

Control UI figure appearance and behavior for uifigure-basedapps (3)

"cyan" "c"[0 1 1]"#00FFFF"

Control UI figure appearance and behavior for uifigure-basedapps (4)

"magenta""m"[1 0 1]"#FF00FF"

Control UI figure appearance and behavior for uifigure-basedapps (5)

"yellow""y"[1 1 0]"#FFFF00"

Control UI figure appearance and behavior for uifigure-basedapps (6)

"black""k"[0 0 0]"#000000"

Control UI figure appearance and behavior for uifigure-basedapps (7)

"white""w"[1 1 1]"#FFFFFF"

Control UI figure appearance and behavior for uifigure-basedapps (8)

"none"Not applicableNot applicableNot applicableNo color

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.

RGB TripletHexadecimal Color CodeAppearance
[0 0.4470 0.7410]"#0072BD"

Control UI figure appearance and behavior for uifigure-basedapps (9)

[0.8500 0.3250 0.0980]"#D95319"

Control UI figure appearance and behavior for uifigure-basedapps (10)

[0.9290 0.6940 0.1250]"#EDB120"

Control UI figure appearance and behavior for uifigure-basedapps (11)

[0.4940 0.1840 0.5560]"#7E2F8E"

Control UI figure appearance and behavior for uifigure-basedapps (12)

[0.4660 0.6740 0.1880]"#77AC30"

Control UI figure appearance and behavior for uifigure-basedapps (13)

[0.3010 0.7450 0.9330]"#4DBEEE"

Control UI figure appearance and behavior for uifigure-basedapps (14)

[0.6350 0.0780 0.1840]"#A2142F"

Control UI figure appearance and behavior for uifigure-basedapps (15)

Window style, specified as one of the following:

  • 'normal' — The figure window is independent of other windows, and the other windows are accessible while the figure is displaying.

  • 'modal' — The figure displays on top of all existing figure windows with normal window style, making them inaccessible as long as the top figure exists and remains modal. However, any new figures created after a modal figure will display.

    When multiple modal windows exist, the most recently created window keeps focus and stays above all other windows until it becomes invisible, or is returned to a normal window style, or is deleted. At that time, focus reverts to the window that last had focus.

  • 'alwaysontop' — The figure displays on top of all other windows, including modal figure windows and windows from non-MATLAB applications. The other windows are still accessible.

Note

These are some important characteristics of the WindowStyle property and some recommended best practices:

  • When you create UI windows, always specify the WindowStyle property. If you also want to set the Resize or Position properties of the figure, then set the WindowStyle property first.

  • You can change the WindowStyle property of a figure at any time, including when the figure is visible and contains children. However on some systems, setting this property might cause the figure to flash or disappear and reappear, depending on the system's implementation of normal and modal windows. For best visual results, set the WindowStyle property at creation time or when the figure is invisible.

UI Figure Modal Window Style Behavior

When WindowStyle is set to 'modal', the UI figure window blocks keyboard and mouse interactions in a UI figure window that was created before it and has its Visible property set to 'on'. For instance, in this example Figure 3 is modal with respect to Figure 2 and Figure 2 is modal with respect to Figure 1.

fig1 = uifigure('Name','Figure 1');fig1.WindowStyle = 'modal';fig2 = uifigure('Name','Figure 2');fig2.WindowStyle = 'modal';fig3 = uifigure('Name','Figure 3');fig3.WindowStyle = 'modal';

The modality hierarchy is not preserved if there is a combination of modal and normal figures in the hierarchy of figures.

Unlike modal figures created with the figure function, modal figures created with the uifigure function do not block access to figures created with the figure function or the MATLAB desktop. Interactions with application windows other than MATLAB are also not blocked.

Typing Ctrl+C when a modal figure has focus causes that figure to revert to a 'normal' WindowStyle property setting. This allows the user to type at the command line.

UI figures with the WindowStyle property set to 'modal' and the Visible property set to 'off' do not behave modally until MATLAB makes them visible. Therefore, you can hide a modal window for later reuse, instead of destroying it.

Modal figures do not display menu children, built-in menus, or toolbars. But, it is not an error to create menus in a modal figure or to change the WindowStyle property setting to 'modal' on a figure with menu children. The Menu objects exist and the figure retains them. If you reset the UI figure WindowStyle property to 'normal', the menus display.

Window state, specified as one of these values:

  • 'normal' — The window displays in a normal state.

  • 'minimized' — The window is collapsed, but you can still execute commands to get or set its properties, to add children, or to create plots in the window.

  • 'maximized' — The window fills the screen. The minimize, restore, and close buttons provided by the operating system appear in the corner of the window. If the window has menus in the normal state, they are present in this state.

  • 'fullscreen' — The window fills the screen. However, the minimize, restore, and close buttons provided by the operating system are hidden. If the window has menus in the normal state, they are present in this state.

Clicking the minimize, maximize, or restore button provided by the operating system sets the WindowState property accordingly. Pressing Ctrl+F11 (Windows® and Linux®) or Ctrl+Command+F (macOS) toggles the 'fullscreen' state. Setting this property on a docked figure or in MATLAB Online™ is not supported.

UI figures cannot be minimized directly from a full screen state.

Position and Size

expand all

Units of measurement, specified as one of the values from this table.

Units ValueDescription
'pixels' (default)

Pixels.

Distances in pixels are independent of your system resolution on Windows and Macintosh systems:

  • On Windows systems, a pixel is 1/96th of an inch.

  • On Macintosh systems, a pixel is 1/72nd of an inch.

On Linux systems, the size of a pixel is determined by your system resolution.

'normalized'These units are normalized with respect to the parent container. The lower-left corner of the container maps to (0,0) and the upper-right corner maps to (1,1).
'inches'Inches.
'centimeters'Centimeters.
'points'Points. One point equals 1/72nd of an inch.
'characters'

These units are based on the default uicontrol font of the graphics root object:

  • Character width = width of the letter x.

  • Character height = distance between the baselines of two lines of text.

To access the default uicontrol font, use get(groot,'defaultuicontrolFontName') or set(groot,'defaultuicontrolFontName').

MATLAB measures all units from the lower left corner of the parent object.

The recommended value is 'pixels', because most MATLAB app building functionality measures distances in pixels.

Note

App Designer supports only pixel units. To create a container that is sized relative to its parent container in App Designer, use a grid layout manager or create an app with auto-reflow. For more information, see Manage Resizable Apps in App Designer.

This property affects the Position property. If you change the Units property, consider returning its value to the default value after completing your computation to avoid affecting other functions that assume the default value.

The order in which you specify the Units and Position properties has these effects:

  • If you specify the Units before the Position property, then MATLAB sets Position using the units you specify.

  • If you specify the Units property after the Position property, MATLAB sets the position using the default Units. Then, MATLAB converts the Position value to the equivalent value in the units you specify.

Location and size of UI figure, excluding borders and title bar, specified as a four-element vector of the form [left bottom width height]. All measurements are in units specified by the Units property.

This property value is identical to the Position property value.

Resizable UI figure, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

When this property is set to 'on', the UI figure is resizable. Otherwise, it is not resizable.

Plotting

expand all

Color map for UIAxes content, specified as an m-by-3 array of RGB (red, green, blue) triplets that define m individual colors.

Example: uifigure('Colormap',[1 0 1; 0 0 1; 1 1 0]) sets the color map to three colors: magenta, blue, and yellow.

MATLAB accesses these colors by their row number.

Transparency map for axes content, specified as a vector of values between 0 and 1, inclusive. The size of the vector can be m-by-1 or 1-by-m. MATLAB accesses alpha values by their index in the vector. Alphamaps can be any length.

Mouse Pointer

expand all

Pointer symbol, specified as one of the values in the following table or as 'custom'. The appearance of the symbol is operating-system dependent.

Value

Resulting Symbol (System Dependent)

'arrow'

Control UI figure appearance and behavior for uifigure-basedapps (16)

'ibeam'

Control UI figure appearance and behavior for uifigure-basedapps (17)

'crosshair'

Control UI figure appearance and behavior for uifigure-basedapps (18)

'watch' (busy system)

Control UI figure appearance and behavior for uifigure-basedapps (19)

'topl' or 'botr'

Control UI figure appearance and behavior for uifigure-basedapps (20)

'topr' or 'botl'

Control UI figure appearance and behavior for uifigure-basedapps (21)

'circle'

Control UI figure appearance and behavior for uifigure-basedapps (22)

'cross'

Control UI figure appearance and behavior for uifigure-basedapps (23)

'fleur'

Control UI figure appearance and behavior for uifigure-basedapps (24)

'left' or 'right'

Control UI figure appearance and behavior for uifigure-basedapps (25)

'top' or 'bottom'

Control UI figure appearance and behavior for uifigure-basedapps (26)

'hand'

Control UI figure appearance and behavior for uifigure-basedapps (27)

Custom Pointer Symbol

To create a custom pointer symbol, programmatically set the Pointer property to 'custom' and use the PointerShapeCData property to define the symbol. See the PointerShapeCData property for more information.

Limitations

Pointer symbols specified by the Pointer property do not display over HTML UI components created with the uihtml function.

Custom pointer symbol, specified as a 16-by-16 matrix (for a 16-by-16 pixel pointer), or as a 32-by-32 matrix (for a 32-by-32 pixel pointer). The figure uses this pointer symbol when you set the Pointer property to 'custom'.

Each element in the matrix defines the brightness level for 1 pixel in the pointer, where the element can have one of these values:

  • 1 — Black pixel.

  • 2 — White pixel.

  • NaN — Transparent pixel, such that underlying screen shows through.

Element (1,1) of the matrix corresponds to the pixel in the upper left corner in the pointer.

Active pixel of the pointer, specified as a two-element vector. The vector contains the row and column indices of a particular element in the PointerShapeCData matrix that corresponds to the desired active pixel. The default value of [1 1] corresponds to the pixel in the upper left corner of the pointer.

If you specify a value outside the range of the PointerShapeCData matrix, then the pointer uses the default active pixel of [1 1] instead.

This property applies only when the Pointer property is set to 'custom'.

Interactivity

expand all

State of visibility, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Display the object.

  • 'off' — Hide the object without deleting it. You still can access the properties of an invisible UI component.

To make your app start faster, set the Visible property to 'off' for all components that do not need to appear at startup.

Changing the size of an invisible container triggers the SizeChangedFcn callback when it becomes visible.

Changing the Visible property of a container does not change the values of the Visible properties of child components. This is true even though hiding the container causes the child components to be hidden.

Target axes in the current UI figure, specified as a UIAxes, Axes, or PolarAxes object, or a graphics object such as a HeatmapChart.

In all UI figures for which axes children exist, there is always a current axes. The current axes does not have to be the topmost axes, and setting an axes to be the current axes does not restack it above all other axes. If a UI figure contains no axes, the get(gcf,'CurrentAxes') command returns an empty array.

Query the CurrentAxes property to get the current axes object without forcing the creation of an axes if one does not exist.

Current object, returned as a child object of the UI figure. MATLAB sets the CurrentObject property to the last object clicked in the UI figure.

Clicking an object whose HandleVisibility property is 'off' sets the CurrentObject property to an empty GraphicsPlaceholder array.

Current point, returned as a two-element vector. The vector contains the (x, y) coordinates of the mouse pointer, measured from the lower-left corner of the UI figure. The values are in units specified by the Units property. If the UI figure is scrollable, the coordinates are measured from the lower-left corner of the scrollable area. The scrollable area is the area that is bounded by the limits of the scroll bars.

The coordinates update when you do any of the following:

  • Press the mouse button within the UI figure.

  • Release the mouse button after pressing it within the UI figure.

  • Press the mouse button within the UI figure, and then release it outside the UI figure.

  • Rotate the scroll wheel within the UI figure.

  • Move the mouse within the figure (without pressing any buttons), as long as the WindowButtonMotionFcn property is not empty.

If the UI figure has a callback that responds to mouse interactions, and you trigger that callback faster than the system can execute the code, the coordinates might not reflect the actual location of the pointer. Instead, they are the location when the callback began execution.

If you use the CurrentPoint property to plot points, the coordinate values might contain rounding error.

Current character, returned as the character of the last key pressed. This property updates when the UI figure has focus while the user presses a key.

Mouse selection type, returned as 'normal', 'extend', 'alt', or 'open'. This property provides information about the last mouse button press that occurred in the UI figure.

This table lists the possible SelectionType values and the user actions that produce those values.

Value

Corresponding Action

'normal'

Click the left mouse button.

'extend'

Any of the following:

  • Shift-click the left mouse button.

  • Click the middle mouse button.

  • Click both left and right mouse buttons.

'alt'

Either of the following:

  • Control-click the left mouse button.

  • Click the right mouse button.

'open'

Double-click any mouse button.

Context menu, specified as a ContextMenu object created with the uicontextmenu function. Use this property to display a context menu when you right-click on a UI figure.

Common Callbacks

expand all

Button down callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user clicks a blank area of the UI figure.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

Use the SelectionType property to determine whether the user pressed modifier keys.

Keyboard Callbacks

expand all

Key-press callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user presses a key while the UI figure or a child component has focus. Pressing a key on a component that accepts keyboard focus (such as an edit field) does not execute the callback unless the component is disabled. You can disable a component by setting the Enable or Editable property to 'off'. In addition, you can disable a Table component without graying it out by setting the Enable property to 'inactive'.

If the user presses multiple keys at approximately the same time, MATLAB detects all the keys.

The KeyPressFcn callback can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of the KeyData object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that appears as a result of pressing the key or keys.

Pressing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are pressed, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key pressed, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is pressed.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'KeyPress''KeyPress''KeyPress''KeyPress'

For more information about specifying callback property values and using callback arguments, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

The CurrentCharacter property also returns character information.

Key-release callback, specified as one of these values

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user releases a key while the UI figure or a child component has focus. Releasing a key on a component that accepts keyboard focus (such as an edit field) does not execute the callback unless the component is disabled. You can disable a component by setting the Enable or Editable property to 'off'. In addition, you can disable a Table component without graying it out by setting the Enable property to 'inactive'.

This callback function can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of the KeyData object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that corresponds to the key or keys that are released.

Pressing and releasing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are released, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key released, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is released.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'KeyRelease''KeyRelease''KeyRelease''KeyRelease'

For more information about specifying callback property values and using callback arguments, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

Window Callbacks

expand all

Close request callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Specify a Callback Function.

MATLAB executes this callback when the app user attempts to close the app. For example, you can code the callback to display a dialog box that asks the app user to confirm or cancel the close operation.

The default value of the CloseRequestFcn callback, 'closereq', unconditionally deletes the figure, destroying the window.

Consider calling the delete function to close the Figure in the CloseRequestFcn callback:

  • In App Designer, call delete(app).

  • For apps created programmatically, call delete(f), where f is the Figure object.

If the CloseRequestFcn callback does not contain a delete command, MATLAB never closes the window. You can always call the delete function to force the window to close.

Example: Code CloseRequestFcn to Display Dialog Box

This example shows how to code the close request function to display a confirmation dialog box asking the user to confirm the close operation. Save the code to a writable folder on your system.

function myCloseReq(src,event)selection = uiconfirm(src,'Close this figure?',... 'Confirm Close'); switch selection case 'OK' delete(src) case 'Cancel' return endend

Now, create a figure and specify myCloseReq for the CloseRequestFcn. Notice that the function handle does not explicitly refer to any input arguments, but the function declaration includes two input arguments. MATLAB passes these arguments automatically when the callback executes. The first argument is the UI component that triggered the callback, and the second argument provides event data to the callback function.

uifigure('CloseRequestFcn',@myCloseReq);

Close the figure window and the confirmation dialog box displays.

Window button down callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user clicks:

  • A blank area of the UI figure.

  • A UI component within the UI figure.

  • A graphics object within the UI figure that supports the ButtonDownFcn property.

For example, clicking an axes object triggers the WindowButtonDownFcn callback.

If the user clicks a UITable component, the callback does not execute unless the Enable property is set to 'off' or 'inactive'.

See the list of properties for a specific graphics object to determine if it supports the ButtonDownFcn property. See Graphics Object Properties for the properties of graphics objects.

Note

The callback executes when the user clicks a uiaxes component, even though uiaxes components do not support the ButtonDownFcn property.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

Window button motion callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

Typically, this callback function executes whenever the user moves the pointer within the UI figure. However, if the user clicks and holds the mouse button and moves the pointer outside the UI figure, the WindowButtonMotionFcn callback executes while the pointer is outside the UI figure.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

Window button up callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user:

  • Releases the mouse button on a blank area of the UI figure.

  • Releases the mouse button on a UI component within the UI figure.

  • Releases the mouse button on a graphics object within the UI figure that supports the ButtonDownFcn property.

For example, releasing the mouse button on an axes object triggers the WindowButtonUpFcn callback.

If the user releases the mouse button on a UITable component, the callback does not execute unless the Enable property is set to 'off' or 'inactive'.

See the list of properties for a specific graphics object to determine if it supports the ButtonDownFcn property. See Graphics Object Properties for the properties of graphics objects.

Button-up actions are associated with button-down actions in the UI figure. The mouse pointer must be inside the UI figure when the button-down action occurs, but it can be outside the figure when the button-up action occurs.

Note

The callback executes when the user releases the mouse button on a uiaxes component, even though uiaxes components do not support the ButtonDownFcn property.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

Window key-press callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user presses a key while the UI figure or a child component has focus. If the user presses multiple keys at approximately the same time, MATLAB detects all the keys.

This callback function can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of the KeyData object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that appears as a result of pressing the key or keys.

Pressing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are pressed, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key pressed, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is pressed.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'WindowKeyPress''WindowKeyPress''WindowKeyPress''WindowKeyPress'

For more information about specifying callback property values and using callback arguments, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

The CurrentCharacter property also returns character information.

Window key-release callback, specified as one of these values

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback function executes when the user releases a key while the UI figure or a child component has focus.

This callback function can access specific information about the user’s interaction with the keyboard. MATLAB passes this information in a KeyData object as the second argument to your callback function. This table lists the properties of the KeyData object.

PropertyDescription

Examples:

a

=

Shift

Shift-a

Character

The character that corresponds to the key or keys that are released.

Pressing and releasing certain keys alone (such as Ctrl, Alt, Shift) does not generate Character data.

'a''=''''A'
Modifier

A cell array containing the names of the modifier keys pressed, such as 'control', 'alt', or 'shift'. If no modifier keys are released, the cell array is empty.

{1x0 cell}{1x0 cell}{'shift'}{'shift'}
Key

The key released, identified by the lowercase label on the key (such as 'pageup'), or a descriptive word (such as 'space').

'a''equal''shift''a'
SourceThe object that has focus when the key is released.Figure objectFigure objectFigure objectFigure object
EventNameThe action that caused the callback function to execute.'WindowKeyRelease''WindowKeyRelease''WindowKeyRelease''WindowKeyRelease'

For more information about specifying callback property values and using callback arguments, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

Window scroll wheel callback, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a functionhandle. Subsequent elements in the cell array are the arguments topass to the callback function.

  • A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.

This callback executes when the user moves the scroll wheel while the UI figure or any of its children have focus. However, other objects can capture scroll wheel movement and interfere with the execution of this callback.

This callback has no effect on the CurrentObject and SelectionType properties.

This callback can access specific information when the user rotates the scroll wheel. MATLAB passes this information in a ScrollWheelData object as the second argument to your callback function. This table lists the properties of the ScrollWheelData object.

Property

Contents

VerticalScrollCount

A positive or negative number that indicates the direction and number of scroll wheel clicks. Scrolling down returns a positive value. Scrolling up returns a negative value.

The vertical scroll count is the sum of all scroll wheel clicks that occurred since the last time the callback executed. Typically, the value is 1 or -1. However, the scroll count can have a larger magnitude if the WindowScrollWheelFcn callback takes a long time to return, or if the user spins the scroll wheel very fast.

VerticalScrollAmount

A constant value of 3.

Source

Object that executes the callback.

EventName'WindowScrollWheel'.

For more information about specifying callback property values and using callback arguments, see Callbacks in App Designer or Create Callbacks for Apps Created Programmatically.

Example: App for Changing x-Axis Limits

This example shows how to create an app that displays a plot. The user can scroll to change the limits of the x-axis. Copy and paste the following code into the editor and run it.

function scroll_wheel% Shows how to use WindowScrollWheelFcn property% f = uifigure('WindowScrollWheelFcn',@figScroll,'Name','Scroll Wheel Demo'); x = 0:.1:40; y = 4.*cos(x)./(x+2); a = axes(f); h = plot(a,x,y); title(a,'Rotate the scroll wheel') function figScroll(~,event) if event.VerticalScrollCount > 0 xd = h.XData; inc = xd(end)/20; x = [0:.1:xd(end)+inc]; re_eval(x) elseif event.VerticalScrollCount < 0 xd = h.XData; inc = xd(end)/20; % Don't let xd = 0 x = [0:.1:xd(end)-inc+.1]; re_eval(x) end end function re_eval(x) y = 4.*cos(x)./(x+2); h.YData = y; h.XData = x; a.XLim = [0 x(end)]; drawnow endend

Notice that the function handle for figScroll does not explicitly refer to any input arguments, but the function declaration includes two input arguments. MATLAB passes these arguments automatically when the callback executes. The first argument is the UI component that triggered the callback, and the second argument provides event data to the callback function.

Callback Execution Control

expand all

Parent/Children

expand all

This property is read-only.

Parent object, returned as a root object.

Children of the Figure object, returned as an empty GraphicsPlaceholder or a one-dimensional array of component objects. The children can be any component, excluding another Figure object.

You cannot add or remove a child component using the Children property. Use this property to view the list of children or to reorder the children. The order of the children in this array reflects the front-to-back order (stacking order) of the components on the screen.

To add a child to this list, set the Parent property of the child component to the Figure object.

Visibility of object handle, specified as 'off', 'callback', or 'on'. This property provides information about the visibility of the Figure object in its parent's list of children. The default value is set to 'off' to prevent the Figure object from becoming the current figure (gcf) and to prevent functions from making unwanted changes to the UI.

This table describes the effect of setting each value:

HandleVisibility ValueDescription
'off'

The Figure object handle is not visible from callback functions or functions that execute in the Command Window. In addition, the object handle is:

  • Not visible in the lists returned by the graphics root Children or CurrentFigure properties.

  • Not returned by functions that access objects by searching the object hierarchy or querying object properties. These functions include gcf, gco, get, findobj, clf, and close.

This option prevents callback functions and functions invoked from the command line from targeting the object and making unintended changes to the UI.

'callback'

The Figure object handle is visible only from within callbacks or functions invoked by callbacks, but not from within functions invoked from the Command Window. In addition, the object handle is not visible in the lists returned by the graphics root Children or CurrentFigure properties.

This option blocks access to the object at the command line, but allows callback functions to access it.

'on'

The Figure object handle is always visible.

Objects are valid even if their HandleVisibility property is set to 'off'. If you have access to an object, you can set and get its properties, and pass it to any function that operates on objects.

Identifiers

expand all

Icon source or file, specified as a character vector, a string scalar, or an m-by-n-by-3 truecolor image array. If you specify a file name, it can be an image file name on the MATLAB path or a full path to an image file. If you plan to share an app with others, put the image file on the MATLAB path to facilitate app packaging.

Supported image formats include JPEG, PNG, GIF, and m-by-n-by-3 truecolor image array. For more information about truecolor image arrays, see Working with Image Types in MATLAB. Animated GIF files display only the first frame.

If sufficient space is not available to display the icon completely at full size, MATLAB scales down the image to fit.

Example: 'icon.png' specifies an icon file on the MATLAB path.

Example: 'C:\Documents\icon.png' specifies a full path to an image file.

Example: fig = uifigure('Icon','peppers.png') creates a UI figure using the specified icon image file.

This property is read-only.

Number of the figure, returned as an integer or empty array.

If the IntegerHandle property is set to 'off', the Number property is empty.

If IntegerHandle is 'on', the Number property is an integer. When you delete the figure, MATLAB reuses the number for the next figure.

Number title, specified as 'off' or 'on', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

When you set this property to 'on', the title of the UI figure includes the phrase 'Figure n', where n is a number.

Both the NumberTitle and IntegerHandle properties must be set to 'on' to show the number in the title.

Use integer handle, specified as 'off' or 'on', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

If you set the IntegerHandle property to 'on', MATLAB finds the lowest integer value that is not used by an existing figure and sets the Number property to that value. If you delete a UI figure, MATLAB can reuse its number on a new figure.

If you set the IntegerHandle property to 'off', MATLAB does not assign an integer value to the UI figure, and it sets the Number property to an empty array.

To show the number in the title bar, both IntegerHandle and NumberTitle must be set to 'on'.

This property is read-only.

Type of graphics object, returned as 'figure'.

Version History

Introduced in R2016a

expand all

To keep a specific UI figure window in front of other windows, set the WindowStyle property to 'alwaysontop'. Unlike modal figures, UI figure windows with this property setting do not restrict keyboard and mouse interactions.

To restrict keyboard and mouse interactions to a specific UI figure window, set the WindowStyle property to 'modal'.

To add a custom icon to a UI figure window, set the Icon property to an image file or an m-by-n-by-3 truecolor array.

See Also

uifigure | groot | App Designer

Topics

  • Default Property Values

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Control UI figure appearance and behavior for uifigure-basedapps (28)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Control UI figure appearance and behavior for uifigure-based
apps (2024)

References

Top Articles
Latest Posts
Article information

Author: Delena Feil

Last Updated:

Views: 6246

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Delena Feil

Birthday: 1998-08-29

Address: 747 Lubowitz Run, Sidmouth, HI 90646-5543

Phone: +99513241752844

Job: Design Supervisor

Hobby: Digital arts, Lacemaking, Air sports, Running, Scouting, Shooting, Puzzles

Introduction: My name is Delena Feil, I am a clean, splendid, calm, fancy, jolly, bright, faithful person who loves writing and wants to share my knowledge and understanding with you.