Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

Adding Components to the GUI

Other topics that may be of interest:

Available Components

The component palette at the left side of the Layout Editor contains the components that you can add to your GUI. You can display it with or without names.

When you first open the Layout Editor, the component palette contains only icons. To display the names of the GUI components, select Preferences from the File menu, check the box next to Show names in component palette, and click OK.

See Creating Menus for information about adding menus to a GUI.

Component

Icon

Description

Push Button

Push buttons generate an action when clicked. For example, an OK button might apply settings and close a dialog box. When you click a push button, it appears depressed; when you release the mouse button, the push button appears raised.

Slider

Sliders accept numeric input within a specified range by enabling the user to move a sliding bar, which is called a slider or thumb. Users move the slider by clicking the slider and dragging it, by clicking in the trough, or by clicking an arrow. The location of the slider indicates the relative location within the specified range.

Radio Button

Radio buttons are similar to check boxes, but radio buttons are typically mutually exclusive within a group of related radio buttons. That is, when you select one button the previously selected button is deselected. To activate a radio button, click the mouse button on the object. The display indicates the state of the button. Use a button group to manage mutually exclusive radio buttons.

Check Box

Check boxes can generate an action when checked and indicate their state as checked or not checked. Check boxes are useful when providing the user with a number of independent choices, for example, displaying a toolbar.

Edit Text

Edit text components are fields that enable users to enter or modify text strings. Use edit text when you want text as input. Users can enter numbers but you must convert them to their numeric equivalents.

Static Text

Static text controls display lines of text. Static text is typically used to label other controls, provide directions to the user, or indicate values associated with a slider. Users cannot change static text interactively.

Pop-Up Menu

Pop-up menus open to display a list of choices when users click the arrow.

List Box

List boxes display a list of items and enable users to select one or more items.

Toggle Button

Toggle buttons generate an action and indicate whether they are turned on or off. When you click a toggle button, it appears depressed, showing that it is on. When you release the mouse button, the toggle button remains depressed until you click it a second time. When you do so, the button returns to the raised state, showing that it is off. Use a button group to manage mutually exclusive toggle buttons.

Table

Use the table button to create a table component. Refer to the uitable function for more information on using this component.

Axes

Axes enable your GUI to display graphics such as graphs and images. Like all graphics objects, axes have properties that you can set to control many aspects of its behavior and appearance. See Axes Properties in the MATLAB Graphics documentation and commands such as the following for more information on axes objects: plot, surf, line, bar, polar, pie, contour, and mesh. See Functions — By Category in the MATLAB Function Reference documentation for a complete list.

Panel

Panels arrange GUI components into groups. By visually grouping related controls, panels can make the user interface easier to understand. A panel can have a title and various borders.

Panel children can be user interface controls and axes as well as button groups and other panels. The position of each component within a panel is interpreted relative to the panel. If you move the panel, its children move with it and maintain their positions on the panel.

Button Group

Button groups are like panels but are used to manage exclusive selection behavior for radio buttons and toggle buttons.

Toolbar

You can create toolbars containing push buttons and toggle buttons. Use the GUIDE Toolbar Editor to create toolbar buttons. Choose between predefined buttons, such as Save and Print, and buttons which you customize with your own icons and callbacks.

ActiveX® Component

ActiveX components enable you to display ActiveX controls in your GUI. They are available only on the Microsoft® Windows® platform.

An ActiveX control can be the child only of a figure, i.e., of the GUI itself. It cannot be the child of a panel or button group.

See ActiveX Control in this document for an example. See Creating COM Objects in the MATLAB External Interfaces documentation to learn more about ActiveX controls.

A Working GUI with Many Components

To see what GUI components look like and how they work, you can open in GUIDE and run an example GUI that demonstrates more than a dozen of them. When you run the GUI, all its component callbacks tell your actions using the GUI and some also update the plot it displays. The GUI, called controlsuite, includes all the components listed in the table in the previous section, Available Components, except for ActiveX controls. It consists of a FIG-file (controlsuite.fig) that opens in GUIDE, and an M-file (controlsuite.m) that opens in the MATLAB Editor.

Viewing the controlsuite Layout and GUI M-File

If you are reading this in the MATLAB Help browser, click the following links to display the GUIDE Layout Editor and the MATLAB Editor with a completed version of the controlsuite example.

When you open controlsuite.fig in GUIDE, it looks like this in the Layout Editor. Click any control outlined in yellow in the following figure to read about how that type of component is programmed, as described in the section Examples: Programming GUIDE GUI Components. Several of the controls are also discussed later in this section.

The GUI contains 15 controls organized within seven panels. The Action Panel contains a static text component that changes to describe the actions a user makes when manipulating the controls. For example, selecting Charlie in the Listbox panel places the word Charlie in the Action Panel. The Membrane data table and plot panel on the right side displays a 3-D surface plot (generated by the membrane function) in an axes at its bottom, and the data for that plot in the table above it. The user can control the view azimuth and the colormap using the two controls in the Plot Controls panel at the bottom center.

Running the controlsuite GUI

When you click the Run Figure button in the Layout Editor, the GUI opens, initializes, and displays itself as shown in the following figure.

The following sections describe several controls and the code they execute (their callbacks). Study the sections of code and click the links to the callbacks below to learn the how the controlsuite M-file controls the GUI.

The Push Button.   When the user clicks the Push Button button, the result show up in the Action Panel as

The M-code that generates the message is part of the pushbutton1_Callback, shown below:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.textStatus, 'String', 'Push button pushed')

This callback is activated when pushbutton1 is clicked. It places the string 'Push button pushed' in the static text field named textStatus using the set function. All the controls in controlsuite perform this action, but some of them do other things as well.

The Toggle Button.   When the user clicks the Toggle Button button, this is the result.

The callback for this button, togglebutton1, contains this M-code:

function togglebutton1_Callback(hObject, eventdata, handles)
% hObject    handle to togglebutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton1

isDown = get(hObject,'Value');

if isDown
    set(handles.textStatus, 'string', 'Toggle down')
else
    set(handles.textStatus, 'string', 'Toggle up')
end

The if block tests the variable isDown, which has been set to the Value property of the toggle button, and writes a different message depending on whether the value is true or false.

The Plot Controls.   The two components of the Plot Controls panel affect the plot of the peaks function as well as rewrite the text in the Action Panel.

The popup, named popupmenu1, contains a list of seven colormap names in its String property, which you can set in the Property Inspector by clicking its Edit icon . Typing the strings into the edit dialog and clicking OK sets all seven colormap names at once.

The popup's callback controls its behavior. GUIDE generates this much of the callback.

function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popupmenu1
%        contents as cell array
%        contents{get(hObject,'Value')} returns selected item
%        from popupmenu1

The callbacks's code adds these statements.

contents       = get(hObject,'String'); 
selectedText   = contents{get(hObject,'Value')};
colormapStatus = [selectedText ' colormap'];
set(handles.textStatus, 'string', colormapStatus);
colormap(selectedText)

The String data is retrieved as a cell array and assigned to contents. The Value property indexes the member of contents that the user just selected to retrieve the name of the colormap That name, selectedText, is composed into a message and placed in the textStatus static text field, and used by the colormap function to reset the colormap. For example, if the user selects autumn from the popup, the surface changes to shades of yellow, orange, and red, as shown in the following cutout from the GUI.

The slider control sets the viewing azimuth, causing the plot to rotate when the user moves its "thumb" or clicks its arrows. Its name is slider1 and its callback is slider1_Callback.

The Data Table.   The table in the upper right corner is a uitable component. When the GUI is created, the table's CreateFcn loads the same membrane data into the table that the plot in the axes below it displays.

The table is by default not editable, but by clicking the small Edit toggle button in its upper left corner the user can edit table values, one at a time. This button is placed on top of the table, but is not actually part of it. The table's CellEditCallback responds to each table cell edit by updating the surface plot and displaying the result of the edit in the Action Panel. Clicking the Edit button again makes the table not editable. See togglebutton2_Callback in the controlsuite M-file for details on how this works.

For another example describing how to couple uitables with graphics, see GUI to Interactively Explore Data in a Table.

Find more about how to work with the GUI components used in controlsuite in Examples: Programming GUIDE GUI Components and in the following sections:

Adding Components to the GUIDE Layout Area

This topic tells you how to place components in the GUIDE layout area and give each component a unique identifier.

  1. Place components in the layout area according to your design.

    • Drag a component from the palette and drop it in the layout area.

    • Click a component in the palette and move the cursor over the layout area. The cursor changes to a cross. Click again to add the component in its default size, or click and drag to size the component as you add it.

    Once you have defined a GUI component in the layout area, selecting it automatically shows it in the Property Inspector. If the Property Inspector is not open or is not visible, double-clicking a component raises the inspector and focuses it on that component.

    The components listed in the following table have additional considerations; read more about them in the sections described there.

    If You Are Adding...Then...
    Panels or button groupsSee Adding a Component to a Panel or Button Group.
    MenusSee Creating Menus
    ToolbarsSee Creating Toolbars
    ActiveX controlsSee Adding ActiveX Controls.

    See Grid and Rulers for information about using the grid.

  2. Assign a unique identifier to each component. Do this by setting the value of the component Tag properties. SeeAssigning an Identifier to Each Component for more information.

  3. Specify the look and feel of each component by setting the appropriate properties. The following topics contain specific information.

This is an example of a GUI in the Layout Editor. Components in the Layout Editor are not active. Saving and Running a GUIDE GUI describes how to generate a functioning GUI.

figure shows placing controls in the layout area

Using Coordinates to Place Components

The status bar at the bottom of the GUIDE Layout Editor displays:

If you select a single component and move it, the first two elements of the position vector (distance from left, distance from bottom) are updated as you move the component. If you resize the component, the last two elements of the position vector (width, height) are updated as you change the size. The first two elements may also change if you resize the component such that the position of its lower left corner changes. If no components are selected, the position vector is that of the figure.

For more information, see Using Coordinate Readouts.

Adding a Component to a Panel or Button Group

To add a component to a panel or button group, select the component in the component palette then move the cursor over the desired panel or button group. The position of the cursor determines the component's parent.

GUIDE highlights the potential parent as shown in the following figure. The highlight indicates that if you drop the component or click the cursor, the component will be a child of the highlighted panel, button group, or figure.

Including Existing Components in Panels and Button Groups.   When you add a new component or drag an existing component to a panel or button group, it will become a member, or child, of the panel or button group automatically, whether fully or partially enclosed by it. However, if the component is not entirely contained in the panel or button group, it appears to be clipped in the Layout Editor. When you run the GUI, the entire component is displayed and straddles the panel or button group border. The component is nevertheless a child of the panel and behaves accordingly. You can use the Object Browser to determine the child objects of a panel or button group. Viewing the Object Hierarchy tells you how.

You can add a new panel or button group to a GUI in order to group any of its existing controls. In order to include such controls in a new panel or button group, do the following. The instructions refer to panels, but you do the same for components inside button groups.

  1. Select the New Panel or New Button Group tool and drag out a rectangle to have the size and position you want.

    The panel will not obscure any controls within its boundary unless they are axes, tables, or other panels or button groups. Only overlap panels you want to nest, and then make sure the overlap is complete.

  2. You can use Send Backward or Send to Back on the Layout menu to layer the new panel behind components you do not want it to obscure, if your layout has this problem. As you add components to it or drag components into it, the panel will automatically layer itself behind them.

    Now is a good time to set the panel's Tag and String properties to whatever you want them to be, using the Property Inspector.

  3. Open the Object Browser from the View menu and find the panel you just added. Use this tool to verify that it contains all the controls you intend it to group together. If any are missing, perform the following steps.

  4. Drag controls that you want to include but don't fit within the panel inside it to positions you want them to have. Also, slightly move controls that are already in their correct positions to group them with the panel.

    The panel highlights when you move a control, indicating it now contains the control. The Object Browser updates to confirm the relationship. If you now move the panel, its child controls move with it.

      Tip   You need to move controls with the mouse to register them with the surrounding panel or button group, even if only by a pixel or two. Selecting them and using arrow keys to move them does not accomplish this. Use the Object Browser to verify that controls are properly nested.

See Defining Panels and Button Groups for more information on how to incorporate panels and button groups into a GUI.

Assigning an Identifier to Each Component

Use the Tag property to assign each component a unique meaningful string identifier.

When you place a component in the layout area, GUIDE assigns a default value to the Tag property. Before saving the GUI, replace this value with a string that reflects the role of the component in the GUI.

The string value you assign Tag is used in the M-file code to identify the component and must be unique in the GUI. To set Tag:

  1. Select Property Inspector from the View menu or click the Property Inspector button .

  2. In the layout area, select the component for which you want to set Tag.

  3. In the Property Inspector, select Tag and then replace the value with the string you want to use as the identifier. In the following figure, Tag is set to mybutton.

Defining User Interface Controls

User interface controls include push buttons, toggle buttons, sliders, radio buttons, edit text controls, static text controls, pop-up menus, check boxes, and list boxes.

To define user interface controls, you must set certain properties. To do this:

  1. Use the Property Inspector to modify the appropriate properties. Open the Property Inspector by selecting Property Inspector from the View menu or by clicking the Property Inspector button .

  2. In the layout area, select the component you are defining.

Subsequent topics describe commonly used properties of user interface controls and offer a simple example for each kind of control:

Commonly Used Properties

The most commonly used properties needed to describe a user interface control are shown in the following table. Instructions for a particular control may also list properties that are specific to that control.

PropertyValueDescription
Enableon, inactive, off. Default is on.Determines whether the control is available to the user
MaxScalar. Default is 1.Maximum value. Interpretation depends on the type of component.
MinScalar. Default is 0.Minimum value. Interpretation depends on the type of component.
Position4-element vector: [distance from left, distance from bottom, width, height].Size of the component and its location relative to its parent.
StringString. Can also be a cell array or character array of strings.Component label. For list boxes and pop-up menus it is a list of the items.
Unitscharacters, centimeters, inches, normalized, pixels, points. Default is characters.Units of measurement used to interpret the Position property vector
ValueScalar or vectorValue of the component. Interpretation depends on the type of component.

For a complete list of properties and for more information about the properties listed in the table, see Uicontrol Properties in the MATLAB documentation. Properties needed to control GUI behavior are discussed in Programming a GUIDE GUI

Push Button

To create a push button with label Button 1, as shown in this figure:

Slider

To create a slider as shown in this figure:

Radio Button

To create a radio button with label Indent nested functions, as shown in this figure:

Check Box

To create a check box with label Display file extension that is initially checked, as shown in this figure:

Edit Text

To create an edit text component that displays the initial text Enter your name here, as shown in this figure:

Static Text

To create a static text component with text Select a data set, as shown in this figure:

Pop-Up Menu

To create a pop-up menu (also known as a drop-down menu or combo box) with items one, two, three, and four, as shown in this figure:

List Box

To create a list box with items one, two, three, and four, as shown in this figure:

Toggle Button

To create a toggle button with label Left/Right Tile, as shown in this figure:

Defining Panels and Button Groups

Panels and button groups are containers that arrange GUI components into groups. If you move the panel or button group, its children move with it and maintain their positions relative to the panel or button group.

To define panels and button groups, you must set certain properties. To do this:

  1. Use the Property Inspector to modify the appropriate properties. Open the Property Inspector by selecting Property Inspector from the View menu or by clicking the Property Inspector button .

  2. In the layout area, select the component you are defining.

Subsequent topics describe commonly used properties of panels and button groups and offer a simple example for each component.

Commonly Used Properties

The most commonly used properties needed to describe a panel or button group are shown in the following table:

Property

Values

Description

Position

4-element vector: [distance from left, distance from bottom, width, height].

Size of the component and its location relative to its parent.

Title

String

Component label.

TitlePosition

lefttop, centertop, righttop, leftbottom, centerbottom, rightbottom. Default is lefttop.

Location of title string in relation to the panel or button group.

Units

characters, centimeters, inches, normalized, pixels, points. Default is characters.

Units of measurement used to interpret the Position property vector

For a complete list of properties and for more information about the properties listed in the table, see the Uipanel Properties and Uibuttongroup Properties in the MATLAB reference documentation. Properties needed to control GUI behavior are discussed in theProgramming a GUIDE GUI.

Panel

To create a panel with title My Panel as shown in the following figure:

Button Group

To create a button group with title My Button Group as shown in the following figure:

Defining Axes

Axes enable your GUI to display graphics such as graphs and images using commands such as: plot, surf, line, bar, polar, pie, contour, and mesh.

To define an axes, you must set certain properties. To do this:

  1. Use the Property Inspector to modify the appropriate properties. Open the Property Inspector by selecting Property Inspector from the View menu or by clicking the Property Inspector button .

  2. In the layout area, select the component you are defining.

Subsequent topics describe commonly used properties of axes and offer a simple example.

Commonly Used Properties

The most commonly used properties needed to describe an axes are shown in the following table:

Property

Values

Description

NextPlot

add, replace, replacechildren. Default is replace

Specifies whether plotting adds graphics, replaces graphics and resets axes properties to default, or replaces graphics only.

Position

4-element vector: [distance from left, distance from bottom, width, height].

Size of the component and its location relative to its parent.

Units

normalized, centimeters, characters, inches, pixels, points. Default is normalized.

Units of measurement used to interpret position vector

For a complete list of properties and for more information about the properties listed in the table, see Axes Properties in the MATLAB documentation. Properties needed to control GUI behavior are discussed in Programming a GUIDE GUI.

See commands such as the following for more information on axes objects: plot, surf, line, bar, polar, pie, contour, imagesc, and mesh. See Function Reference in the MATLAB Function Reference documentation for a complete list.

Many of these graphing functions reset axes properties by default, according to the setting of its NextPlot property, which can cause unwanted behavior in a GUI, such as resetting axis limits and removing axes context menus and callbacks. See the next section and also Adding Axes in the Creating GUIs Programmatically section for information on details on setting the NextPlot axes property.

Axes

To create an axes as shown in the following figure:

Defining Tables

Tables enable you to display data in a two dimensional table. You can use the Property Inspector to get and set the object property values.

Commonly Used Properties

The most commonly used properties of a table component are listed in the table below. These are grouped in the order they appear in the Table Property Editor. Please refer to uitable command documentation for detail of all the table properties:

GroupPropertyValuesDescription
ColumnColumnName1-by-n cell array of strings | {'numbered'} | empty matrix ([])The header label of the column.
ColumnFormatCell array of stringsDetermines display and editablility of columns
ColumnWidth1-by-n cell array or 'auto'Width of each column in pixels; individual column widths can also be set to 'auto'
ColumnEditablelogical 1-by-n matrix | scalar logical value | empty matrix ([])}Determines data in a column as editable
RowRowName1-by-n cell array of stringsRow header label names
ColorBackgroundColorn-by-3 matrix of RGB triplesBackground color of cells
RowStriping{on} | offColor striping of table rows
DataDataMatrix or cell array of numeric, logical, or character data Table data.

Creating a Table

To create a GUI with a table in GUIDE as shown, do the following:

Drag the table icon on to the Layout Editor and right click in the table. Select Table Property Editor from its pop-up context menu. You can also select Table Property Editor from the Tools menu when you select a table by itself.

Using the Table Property Editor.   When you open it this way, the Table Property Editor displays theColumn pane. You can also open it from the Property Inspector by clicking one of its Table Property Editor icons , in which case the Table Property Editor opens to display the pane appropriate for the property you clicked.

Clicking items in the list on the left hand side of the Table Property Editor changes the contents of the pane to the right . Use the items to activate controls for specifying the table's Columns, Rows, Data, and Color options.

The Columns and Rows panes each have a data entry area where you can type names and set properties. on a per-column or per-row basis. You can edit only one row or column definition at a time. These panes contain a vertical group of five buttons for editing and navigating:

ButtonPurposeAccelerator Keys
  WindowsMacintosh
InsertInserts a new column or row definition entry below the current oneInsertInsert
DeleteDeletes the current column or row definition entry (no undo)Ctrl+DCmd+D
CopyInserts a Copy of the selected entry in a new row below itCtrl+PCmd+P
UpMoves selected entry up one rowCtrl+
uparrow
Cmd+
uparrow
DownMoves selected entry down one rowCtrl+
downarrow
Cmd+
downarrow


Keyboard equivalents only operate when the cursor is in the data entry area. In addition to those listed above, typing Ctrl+T or Cmd+T selects the entire field containing the cursor for editing (if the field contains text).

To save changes to the table you make in the Table Property Editor, click OK, or click Apply commit changes and keep on using the Table Property Editor.

Set Column Properties.   Click Insert to add two more columns.

Select Show names entered below as the column headers and set the ColumnName by entering Rate, Amount, Available, and Fixed/Adj in Name group. for the Available and Fixed/Adj columns set the ColumnEditable property to on. Lastly set the ColumnFormat for the four columns

For the Rate column, select Numeric. For the Amount Column select Custom and in the Custom Format Editor, choose Bank.

Leave the Available column at the default value. This allows MATLAB to chose based on the value of the Data property of the table. For the Fixed/Adj column select Choice List to create a pop-up menu. In the Choice List Editor, click Insert to add a second choice and type Fixed and Adjustable as the 2 choices.

Set Row Properties.   In the Row tab, leave the default RowName, Show numbered row headers.

Set Data Properties.   Specify the value of the Data you want in the table. You need create Data in the MATLAB command window before you specify it in GUIDE. For this example, type:

dat =  {6.125, 456.3457, true,  'Fixed';...
6.75,  510.2342, false, 'Adjustable';...
7,     658.2,    false, 'Fixed';};

In the Table Property Editor, select the data that you defined and select Change data value to the selected workspace variable below.

Set Color Properties.   Specify the BackgroundColor and RowStriping for your table in the Color tab.

You can change other uitable properties to the table via the Property Inspector.

Adding ActiveX Controls

When you drag an ActiveX component from the component palette into the layout area, GUIDE opens a dialog box, similar to the following, that lists the registered ActiveX controls on your system.

  1. Select the desired ActiveX control. The right panel shows a preview of the selected control.

  2. Click Create. The control appears as a small box in the Layout Editor.

  3. Resize the control to approximately the size of the square shown in the preview pane. You can do this by clicking and dragging a corner of the control, as shown in the following figure.

    Resizing the control by clicking and dragging

When you select an ActiveX control, you can open the ActiveX Property Editor by right-clicking and selecting ActiveX Property Editor from the context menu or clicking the Tools menu and selecting it from there.

See ActiveX Control for information about programming a sample ActiveX control and an example.

Working with Components in the Layout Area

This topic provides basic information about selecting, copying, pasting, and deleting components in the layout area.

Other topics that may be of interest are

Selecting Components

You can select components in the layout area in the following ways:

In some cases, a component may lie outside its parent's boundary. Such a component is not visible in the Layout Editor but can be selected by dragging a rectangle that encloses it or by selecting it in the Object Browser. Such a component is visible in the active GUI.

See Viewing the Object Hierarchy for information about the Object Browser.

Copying, Cutting, and Clearing Components

Use standard menu and pop-up menu commands, toolbar icons, keyboard keys, and shortcut keys to copy, cut, and clear components.

Copying.   Copying places a copy of the selected components on the clipboard. A copy of a panel or button group includes its children.

Cutting.   Cutting places a copy of the selected components on the clipboard and deletes them from the layout area. If you cut a panel or button group, you also cut its children.

Clearing.   Clearing deletes the selected components from the layout area. It does not place a copy of the components on the clipboard. If you clear a panel or button group, you also clear its children.

Pasting and Duplicating Components

Pasting.   Use standard menu and pop-up menu commands, toolbar icons, and shortcut keys to paste components. GUIDE pastes the contents of the clipboard to the location of the last mouse click. It positions the upper-left corner of the contents at the mouse click.

Consecutive pastes place each copy to the lower right of the last one.

Duplicating.   Select one or more components that you want to duplicate, then do one of the following:

Front-to-Back Positioning

MATLAB figures maintain separate stacks that control the front-to-back positioning for different kinds of components:

You can control the front-to-back positioning of components that overlap only if those components are in the same stack. For overlapping components that are in different stacks:

The Layout Editor provides four operations that enable you to control front-to-back positioning. All are available from the Layout menu, which is shown in the following figure.

Locating and Moving Components

You can locate or move components in one of the following ways:

Another topic that may be of interest is

Using Coordinate Readouts

Coordinate readouts indicate where a component is placed and where the mouse pointer is located. Use these readouts to position and align components manually. The coordinate readout in the lower right corner of the Layout Editor shows the position of a selected component or components as [xleft ybottom width height]. These values are displayed in units of pixels, regardless of the coordinate units you select for components.

If you drag or resize the component, the readout updates accordingly. The readout to the left of the component position readout displays the current mouse position, also in pixels. The following readout example shows a selected component that has a position of [35, 30, 180, 180], a 180-by-180 pixel object with a lower left corner at x=35 and y=30, and locates the mouse position at [200, 30].

When you select multiple objects, the Position readout displays numbers for x, y, width and height only if the objects have the same respective values; in all other cases it displays 'MULTI'. For example, if you select two check boxes, one with Position [250, 140, 76, 20] pixels and the other with position [250, 190, 68, 20] pixels, the Position readout indicates [250, MULTI, MULTI, 20].

Dragging Components

Select one or more components that you want to move, then drag them to the desired position and drop them. You can move components from the figure into a panel or button group. You can move components from a panel or button group into the figure or into another panel or button group.

The position of the cursor when you drop the components also determines the parent of all the selected components. Look for the highlight as described in Adding a Component to a Panel or Button Group.

In some cases, one or more of the selected components may lie outside its parent's boundary. Such a component is not visible in the Layout Editor but can be selected by dragging a rectangle that encloses it or by selecting it in the Object Browser. Such a component is visible in the active GUI.

See Viewing the Object Hierarchy for information about the Object Browser.

Using Arrow Keys to Move Components

Select one or more components that you want to move, then press and hold the arrow keys until the components have moved to the desired position. Note that the components remain children of the figure, panel, or button group from which you move them, even if they move outside its boundaries.

Setting the Component's Position Property

Select one or more components that you want to move. Then open the Property Inspector from the View menu or by clicking the Property Inspector button .

  1. In the Property Inspector, scroll to the Units property and note whether the current setting is characters or normalized. Click the button next to Units and then change the setting to inches from the pop-up menu.

  2. Click the + sign next to Position. The Property Inspector displays the elements of the Position property.

  3. If you have selected

    • Only one component, type the x and y coordinates of the point where you want the lower-left corner of the component to appear.

    • More than one component, type either the x or the y coordinate to align the components along that dimension.

  4. Reset the Units property to its previous setting, either characters or normalized.

Resizing Components

You can resize components in one of the following ways:

Dragging a Corner of the Component

Select the component you want to resize. Click one of the corner handles and drag it until the component is the desired size.

Setting the Component's Position Property

Select one or more components that you want to resize. Then open the Property Inspector from the View menu or by clicking the Property Inspector button .

  1. In the Property Inspector, scroll to the Units property and note whether the current setting is characters or normalized. Click the button next to Units and then change the setting to inches from the pop-up menu.

  2. Click the + sign next to Position. The Property Inspector displays the elements of the Position property.

  3. Type the width and height you want the components to be.

  4. Reset the Units property to its previous setting, either characters or normalized.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS