uifigure

Create figure for designing apps

Description

example

fig = uifigure creates a figure for building a user interface and returns the Figure object. This is the type of figure that App Designer uses.

example

fig = uifigure(Name,Value) specifies figure properties using one or more Name,Value pair arguments.

Examples

collapse all

fig = uifigure;

Create a UI figure with a specific title.

fig = uifigure('Name','Plotted Results');

Get the Position property value.

p = fig.Position
ans =

   680   678   560   420

Code the CloseRequestFcn callback to open a modal Confirmation dialog box when the user tries to close the window.

Copy and paste this code into the MATLAB® Editor, and then run closeFig.

function closeFig

fig = uifigure('Position',[100 100 425 275]);
fig.CloseRequestFcn = @(fig,event)my_closereq(fig);

    function my_closereq(fig,selection)
        
        selection = uiconfirm(fig,'Close the figure window?',...
            'Confirmation');
          
        switch selection
            case 'OK'
                delete(fig)
                
            case 'Cancel'
                return
        end
        
    end

end

Click the figure close button. The Confirmation dialog box opens.

Change the mouse pointer symbol that displays when you hover over a push button.

This program file, called setMousePointer.m, shows you how to:

  • Create a UI figure which executes custom code when the mouse is moved over a button. To do this, use the @ operator to assign the mouseMoved function handle to the WindowButtonMotionFcn property of the figure.

  • Create a push button and specify its coordinates and label.

  • Create a callback function called mouseMoved with the custom code you want to execute when the mouse moves over the button. In the function, query the CurrentPoint property to determine the mouse pointer coordinates. Set the Pointer property to 'hand' if the pointer coordinates are within the push button coordinates.

Run setMousePointer. Then move the mouse over the push button to see the mouse pointer symbol change.

function setMousePointer
    fig = uifigure('Position',[500 500 375 275]);
    fig.WindowButtonMotionFcn = @mouseMoved;

    btn = uibutton(fig);
    btnX = 50;
    btnY = 50;
    btnWidth = 100;
    btnHeight = 22;
    btn.Position = [btnX btnY btnWidth btnHeight];
    btn.Text = 'Submit Changes';

      function mouseMoved(src,event)
          mousePos = fig.CurrentPoint;

          if  (mousePos(1) >= btnX) && (mousePos(1) <= btnX + btnWidth) ...
                        && (mousePos(2) >= btnY) && (mousePos(2) <= btnY + btnHeight)

              fig.Pointer = 'hand';
          else

              fig.Pointer = 'arrow';
          end

      end

end

Input Arguments

collapse all

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Name','My App' specifies My App as the title of the UI figure.

The properties listed here are a subset of the available properties. For the full list, see UI Figure Properties.

Name of the figure, specified as a character vector or a string scalar.

Example: uifigure('Name','Results') sets the name of the figure to 'Results'.

In App Designer, the default value of the Name property is 'MATLAB App'.

Location and size of the UI figure, excluding borders and title bar, specified as a four-element vector of the form [left bottom width height].

This table describes each element in the vector.

ElementDescription
leftDistance from the left edge of the primary display to the inner left edge of the UI figure window. This value can be negative on systems that have more than one monitor.
bottomDistance from the bottom edge of the primary display to the inner bottom edge of the UI figure window. This value can be negative on systems that have more than one monitor.
widthDistance between the right and left inner edges of the UI figure.
heightDistance between the top and bottom inner edges of the UI figure.

Limitations

  • Currently, you cannot pass a Figure object created with the uifigure function to the print function. If you attempt to do so, MATLAB throws an error. For more information, see Display Graphics in App Designer.

Introduced in R2016a