MATLAB Creating Graphical User Interfaces

(Barry) #1
Adjust Programmatic UI Layouts Interactively

Note:The following sections describe some techniques for interactively refining the
appearance of UIs. If you are building a UI that opens a saved FIG-file, re-saving that
file will preserve most of the properties you interactively change. If your program file
creates a new figure whenever you open it, then you must specify all changed properties
in the program file itself to keep the UI up-to-date.


Set Positions of Components Interactively


If you do not like the initial positions or other properties of UI components, you can make
manual adjustments to them. By placing the figure in plot edit mode, you can use your
mouse to move, resize, align, and change various components properties. Then, you can
read out the values of properties you changed and copy them into your UI code file to
initialize the components.


To set position in plot edit mode:


1
Enter plot edit mode. Click the Arrow tool , or select Edit Plot from the Tools
menu. If your figure has no menus or toolbar, type plotedit on in the Command
Window.


2 Select a component. Click the left mouse button while over the component you are
editing.


3 Move and resize the component. Click within it and drag to move it to a new location.
Click a square black handle and drag to change its shape. Use arrow keys to make
small adjustments.


4 Make sure that you know the handle of the component you have manipulated. In the
following code, the handle is a variable named object_handle.


5 Get the component’s Position value from the Property Inspector. Execute this
command to open the Property Inspector.


inspect
Or, use dot notation to get the value at the command prompt.

object_handle.Position
ans =
15.2500 333.0000 106.0000 20.0000

6 Assign the Position property to that value (ans).


object_handle.Position = [15.2500 333.0000 106.0000 20.0000];
Free download pdf