My UI panel doesn't scale up

9 次查看(过去 30 天)
Hello I'm trying to create a panel within a figure. When the figure is maximised the child panel should also maximise as well. In my case when I maximise it maintains the definitions it has when the function is called. However when the uifigure (parent figure) is scaled down to a size smaller than the panel's (child) dimensions at the time of calling, the panel shrinks as it's supposed to. I've attached the callback function that opens the uifigure and the its uipanel child. Any help would be appreciated
%Open the X and Y table window
x_y_window=uifigure('Name','X Y Values');
x_y_window.AutoResizeChildren='on';
size_of_my_window=x_y_window.Position;
% Create a panel for the X setup and data
x_panel=uipanel('Parent',x_y_window);
%X panel configuration
x_panel.Scrollable='on';
x_panel.Position=[10,size_of_my_window(2)/3,size_of_my_window(3)-20,size_of_my_window(4)/2];
% X panel visualization
x_panel.Title='X Value Setup';
x_panel.TitlePosition='centertop';

回答(1 个)

Deepak
Deepak 2024-9-3
Hi John,
I understand that you have created a panel within a UI figure in App Designer, and when you maximize the figure, the child panel does not maximize with it (it maintains its original dimensions). However, when you minimize the figure, the panel also minimizes as expected.
In the code, you have set the “AutoResizeChildren” property of parent figure to “on”, and on investigating I found that this is the expected behavior of the property. When “AutoResizeChildren” property is set as “on”, the child element minimizes when the parent figure is minimized, but the child element maintains its default size when the parent figure is maximized.
A possible workaround, to resize the child panel to always match the parent figure size, can be to create a custom size changed function, and set the “AutoResizeChildren” of parent figure to “off”. The custom function needs to be assigned to “SizeChangedFcn” property of parent UI figure, so that it maintains the size of child panel whenever the size of parent UI figure changes.
Below is the App Designer code that addresses this task:
x_y_window=uifigure('Name','X Y Values');
x_y_window.AutoResizeChildren='off';
% Create a panel for the X setup and data
x_panel=uipanel('Parent',x_y_window);
%X panel configuration
function customSizeChangedFunction(src, ~)
% Get the current size of the uifigure
size_of_my_window = src.Position;
% Calculate new position for the panel to fill the entire window
x_panel.Position = [10, 10, size_of_my_window(3) - 20, size_of_my_window(4) - 20];
end
% Attach the custom size change function to the SizeChangedFcn of the uifigure
x_y_window.SizeChangedFcn = @customSizeChangedFunction;
% Initial call to set the position
customSizeChangedFunction(x_y_window);
% X panel visualization
x_panel.Title='X Value Setup';
x_panel.TitlePosition='centertop';
Attaching the documentation of “uipanel” in App Designer for reference:
I anticipate this will solve the problem.

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by