- The container becomes visible for the first time.
- The container is visible while its drawable area changes.
- The container becomes visible for the first time after its drawable area changes. This
situation occurs when the drawable area changes while the container is invisible and
becomes visible later.
NoteTypically, the drawable area changes at the same time the outer bounds change.
However, adding or removing menu bars or tool bars to a figure causes the outer bounds
to change while the drawable area remains constant. Therefore, the SizeChangedFcn
callback does not execute when you add or remove menu bars or tool bars.
This app is a resizable version of the simple app defined in “Example of a Simple Layout”
on page 9-29. This code includes a figure SizeChangedFcn callback called resizeui.
The resizeui function calculates new Position values for the button and axes when
the user resizes the window. The button appears to be stationary when the user resizes
the window. The axes scales with the figure.
function myui
% Add the UI components
hs = addcomponents;
% Make figure visible after adding components
hs.fig.Visible = 'on';
function hs = addcomponents
% Add components, save handles in a struct
hs.fig = figure('Visible','off',...
'Tag','fig',...
'SizeChangedFcn',@resizeui);
hs.btn = uicontrol(hs.fig,'String',...
'Plot Sine',...
'Callback',@plotsine,...
'Tag','button');
hs.ax = axes('Parent',hs.fig,...
'Units','pixels',...
'Tag','ax');
end
function plotsine(hObject,event)
theta = 0:pi/64:6*pi;
y = sin(theta);
Lay Out a UI Programmatically