User`s guide
15 Examples of GUIs Created Programmatically
Select Units. The prepareL ayou t function decides what units to use based
on the G UI’s resizability. It uses
strcmpi todeterminethevalueoftheGUI’s
Resize property. Depending on the outcome, it sets the
Units properties of all
the objects to either
Normalized or Characters.
% Make the GUI run properly across multiple p latforms by using
% the proper units
if strcmpi(g et(t opContainer, 'Resiz e'), 'on')
set(allObjects(isprop(allObjects,'Unit s')),...
'Units','Normalized');
else
set(allObjects(isprop(allObjects,'Unit s')),...
'Units','Characters');
end
For a resizable figure, normalized units map the lower-left corner of the
figure and of each component to (0,0) and the u pper-right corner to (1.0,1.0).
Because of this, component size is automatically adjusted to its parent’s size
when the GUI is displayed.
For a nonresizable figure, character units automatically adjusts the size and
relative spacing of components as the GUI displays on different computers.
Character units are defined by characters from the default system font. The
width of a character unit equals the width of the letter
x in the system font.
The height of a character unit is the distance between the baselines of two
lines of text. Note that character units are not square.
Make a GUI Modal
iconEditor is a modal figure. Modal figures remain stacked above all normal
figures and the MATLAB command window. This forces the user to respond
without being able to interact with other windows. iconEditor makes the
main figure modal by setting its
WindowStyle property to modal.
hMainFigure = figure(...
...
'WindowStyle','modal',...
See the Figure Properties documentation for more information about usin g
the
WindowStyle property.
15-76