Decrease Existing UIGridLayout RowHeight (or ColumnWidth)

9 次查看(过去 30 天)
I'm trying to decrease an existing uigridlayout's number of rows and columns. Below I created the figure and grid.
fig = uifigure; % make uifigure
g = uigridlayout(fig); % put uigridlayout in fig
g.RowHeight = {'1x' '1x' '1x' '1x'}; % assign to uigridlayout 4 rows
g.ColumnWidth = {'1x' '1x'}; % assign to uigridlayout 2 columns
So, it already exists and has a specified row height and column width dimensions. And I want to change the number of rows and columns in this existing uigridlayout (g)... instead of deleting it and making a new one with the desired number of rows and columnns (e.g. a grid with 3 rows and 3 columns).
I am able to add rows or columns -->
g.ColumnWidth = {'1x' '1x' '1x'} % assign greater amount of columns to g.ColumnWidth property
output -->
g =
GridLayout with properties:
RowHeight: {'1x' '1x' '1x' '1x'}
ColumnWidth: {'1x' '1x' '1x'}
But I can't seem to be able to remove rows or columns -->
g.RowHeight = {'1x' '1x' '1x'} % assign lower amount of columns to g.RowHeight property
output -->
g =
GridLayout with properties:
RowHeight: {'1x' '1x' '1x' '1x'}
ColumnWidth: {'1x' '1x' '1x'}
How do I decrease the number of rows or columns in this existing uigridlayout?

回答(1 个)

Amith
Amith 2024-7-17
Hi Calvin,
According to the MathWorks GridLayout properties documentation ( https://www.mathworks.com/help/matlab/ref/matlab.ui.container.gridlayout-properties.html), altering certain aspects of a layout can impact the value of this property. For instance, adding more components to a fully populated grid will adjust the grid size to accommodate the new components.
Modifying the ColumnWidth property in a grid layout that already contains components does not change the layout of those components. For example, if you attempt to dynamically delete a column that contains components, the ColumnWidth property will not change until you relocate those components out of that column.
The same principles apply to the RowHeight property as well.
Hope this helps!

类别

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