- use relative units (simpler, however objects change size)
- 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.
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
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:
If you prefer 2. then depending on your version use one of:
답변 (1개)
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:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!