MATLAB Creating Graphical User Interfaces

(Barry) #1

6 Lay Out a UI Using GUIDE


Include 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 program, 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. “View the GUIDE Object Hierarchy” on page 6-119 tells you how.

You can add a new panel or button group to a UI 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.
Free download pdf