figure resize behavior control: from bottom or from top

2 次查看(过去 30 天)
Hi, I encountered a problem when I resized a figure: The aim of resizing is to manually drag the top/bottom boundary to adjust the panel size, in order to hide the label and only show the buttons. However, the reality is that no matter where I drag, it is the top space hidden, but the space between the label and bottom remains constant. I can only hide the buttons or hide the buttons and label together, but I cannot find a way to resize to keep the bottom. Is there a way to reverse the direction of resizing?
fig = figure('Name','GUI with Buttons and Labels','NumberTitle','off','Position',[100 100 400 300]);
% Create buttons
btn1 = uicontrol(fig,'Style','pushbutton','String','Button 1','Position',[50 200 100 30]);
btn2 = uicontrol(fig,'Style','pushbutton','String','Button 2','Position',[150 200 100 30]);
btn3 = uicontrol(fig,'Style','pushbutton','String','Button 3','Position',[250 200 100 30]);
% Create labels
lbl1 = uicontrol(fig,'Style','text','String','Label 1','Position',[50 150 100 30]);
lbl2 = uicontrol(fig,'Style','text','String','Label 2','Position',[150 150 100 30]);
lbl3 = uicontrol(fig,'Style','text','String','Label 3','Position',[250 150 100 30]);
  1 个评论
Stephen23
Stephen23 2024-8-26
编辑:Stephen23 2024-8-26
"Is there a way to reverse the direction of resizing?"
No: by definition all positions are measured from the bottom left. You have two main optons:
  1. use relative units (simpler, however objects change size)
  2. if using absolute units define a callback that gets triggered by a resize. Within the callack define all of the positions in terms of the current figure size. You can use the same callback when the figure is created.
If you prefer 2. then depending on your version use one of:

请先登录,再进行评论。

回答(1 个)

Jacob Mathew
Jacob Mathew 2024-8-26
Hey Raym,
I understand that you want to resize the App’s “UIFigure” such that the buttons don’t move. To achieve this, you can use the “Grid Layout”. This grid then handles the position and layout of the elements. However, you might need to adapt some of the code you have written to account for this layout change.
An example app without grid layout:
An example app with Grid Layout:

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by