Clear Filters
Clear Filters

Expand GUI in App UIFigure by a button for to extend the showing

7 views (last 30 days)
I'm trying to expand down part of the UIFigure of a MATLAB App by a button push.
As example:
from: - to ->
I tryied to change the weight of the figure but it does not work properly:
posicio_actual = app.UIFigure.Position; % Exemple : 666 346 588 389 [posX, posY, amplada, llargada]
posicio_actual(4) = posicio_actual(4) + 150;
app.UIFigure.Resize = 'off';
app.UIFigure.AutoResizeChildren = 'off';
app.UIFigure.Position = posicio_actual;
But this is the result:
The below part does not show.
Thank you!

Accepted Answer

Voss on 15 Jul 2022
The Position of each component (specifically Position([1 2]), which are the x- and y-coordinates of the lower-left corner of the component) is measured from the bottom-left corner of its parent container (i.e., figure/uifigure/uipanel/whatever), so when the uifigure's height increases by 150 pixels, in order to do what you want, you actually need to move all the components in the uifigure up by 150 pixels at the same time. (Also, since the uifigure is expanding downward, it makes sense to move the bottom of the uifigure down by 150 pixels so that the top edge remains in the same place it was.)
Here is an example with a traditional figure, where the pushbutton toggles the state of the figure between "expanded" and "collapsed" (you can run it and make sure it does what you want, then apply the same logic to your app):
handles = struct();
handles.figure = figure('Units','pixels');
handles.top_ax = axes( ...
'Units','pixels', ...
'Position',[30 30 200 200]);
handles.bottom_ax = axes( ...
'Units','pixels', ...
'Position',[30 -120 400 90]);
handles.pushbutton = uicontrol( ...
'Units','pixels', ...
'Position',[260 30 70 26], ...
'String','Expand', ...
function cb_expand(src,~,do_expand)
handles = guidata(src);
dy = 150;
if ~do_expand
dy = -dy;
pos = get(handles.figure,'Position');
pos([2 4]) = pos([2 4])+[-dy dy];
pos = get(handles.top_ax,'Position');
pos(2) = pos(2)+dy;
pos = get(handles.bottom_ax,'Position');
pos(2) = pos(2)+dy;
pos = get(handles.pushbutton,'Position');
pos(2) = pos(2)+dy;
if do_expand
new_str = 'Collapse';
new_str = 'Expand';
set(handles.pushbutton, ...
'String',new_str, ...

More Answers (0)


Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!