Manage Grid Layout after removing Children
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I am developing an app where I use the uigridlayout funcionality. I am adding several panels to this Grid layout, each one in a different row (I am using a single column).
I want to remove one of the Children elements and automatically adjust the RowHeight property of the grid layout, as well as the position of the other panels.
As an example, imagine I have 5 panels in a grid layout. The initial RowHeight property of the uigridlayout object is set to {'1x', '1x', '1x', '1x', '1x',}.
When panel number two is removed, the RowHeight property should change to {'1x', '1x', '1x', '1x'}, and the positions of the other panels should change accordingly (panel 1 remains unchanged, panel 3 moves to row 2, panel 4 moves to row 4, etc).
I've tried several ways to achieve this without success.
Is there any way to do it without setting each panels' row?
0 commentaires
Réponse acceptée
NIKOLAOS
le 25 Nov 2023
Modifié(e) : NIKOLAOS
le 25 Nov 2023
I had a similar problem you can try deleting the element of the uigridlayout and reloading the remaining
UIFigure = uifigure();
% Create a GridLayout with 1 column and 5 rows
panelContainer = uigridlayout(UIFigure);
panelContainer.ColumnWidth = {'1x'};
panelContainer.RowHeight = {'1x','1x','1x','1x','1x'};
p1 = uipanel(panelContainer);
p1.Title = 'P1';
p1.Layout.Row = 1;
p2 = uipanel(panelContainer);
p2.Title = 'P2';
p2.Layout.Row = 2;
p3 = uipanel(panelContainer);
p3.Title = 'P3';
p3.Layout.Row = 3;
p4 = uipanel(panelContainer);
p4.Title = 'P4';
p4.Layout.Row = 4;
p5 = uipanel(panelContainer);
p5.Title = 'P5';
p5.Layout.Row = 5;
delete(p2);
%reload all the children that remain
children = panelContainer.Children;
for k = 1:numel(children)
children(k).Layout.Row = k;
end
if i understand your quention this should do the job and have them all in the same height without leaving a gap between them. Now i dont understand the last part about not setting each panel's row how else do you want them to move inside the gridlayout? Matlab as of my knowledge does not rearrange components if they are not deleted from the bottom.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!