Graphics Previous page   Next Page

Using Panel Containers in Figures -- UIPanels

Figures can contain axes and user interface objects directly, or you can parent these objects to uipanels, which you then parent to a figure. Uipanels are useful for the design of GUIs because they enable you to define subregions in a figure in which you can lay out components.

MATLAB interprets the Position property of all objects parented to a uipanel relative to the uipanel's position. If you move the uipanel, the children automatically move with it.

Uipanels can also contain other uipanels, as well as axes, uicontrols, and uibuttongroups. See the uipanel reference page for more information on uipanels.

Figure Resize Functions

Containing various parts of a GUI in uipanels simplifies the process of programming figure resize behavior because you can write a separate resize function for each panel. The following example illustrates how to do this.

Example -- Using Figure Panels

This example uses three uipanel objects as containers for the GUI's components. All three uipanels are then parented to the figure, as shown in the following containment hierarchy.

Here is a picture of the GUI with some data plotted in the axes.

Complete Example Code

This GUI enables you to select workspace variables from a list box and select a plot type from a pop-up menu. You can add plots to the existing graph by clicking the Hold toggle button and initiate the plot by clicking the Create Plot button.

Use the link above to run the example and open the GUI code in the MATLAB editor.

Creating the Uipanels

The following code shows the definition of the figure and the bottom panel. Setting Units to characters ensures that your GUI is properly sized on different computer systems. The Position property specifies the location and size of each component in units set by the Units property.

Programming the Resize Functions

As you resize the figure, MATLAB calls the figure resize function (specified by the object's ResizeFcn property), which, in this example, computes a new size for each uipanel. Because the figure resize function resizes the uipanels, MATLAB automatically calls the resize function of each uipanel once the figure resize function completes execution. The uipanel resize functions then adjust the sizes and locations of the components they contain.

The following diagram illustrates the sequence of events that occurs when a user resizes the figure.

The following code shows the figure, bottom panel, and right panel resize functions. As each function is called, it sets the object's size and position to values that are proportional to the original layout.

See Nested Functions for more information.

Note that the center panel does not need a resize function because the axes automatically resize to fit the container (either a figure or uipanel).

To see the complete code listing for this example, see Complete Example Code.

Previous page  Objects That Can Contain Other Objects Grouping Objects Within Axes -- hgtransform Next page

© 1994-2005 The MathWorks, Inc.