figure resize behavior control: from bottom or from top

2 visualizaciones (últimos 30 días)
raym
raym el 26 de Ag. de 2024
Respondida: Jacob Mathew el 26 de Ag. de 2024
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 comentario
Stephen23
Stephen23 el 26 de Ag. de 2024
Editada: Stephen23 el 26 de Ag. de 2024
"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:

Iniciar sesión para comentar.

Respuestas (1)

Jacob Mathew
Jacob Mathew el 26 de Ag. de 2024
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:

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by