how to get uitable extent within uifigure
조회 수: 14 (최근 30일)
이전 댓글 표시
I want to fit uitable size according to its data. When uitable is used within a figure, it is easy to set correct values to the Position(3:4) property using the corresponding Extent(3:4) values with some small offsets to avoid useless scrolling bars. When uitable is built within an uifigure, there is no extent property available. How to get around this strange limitation? Knowing the width of each column the uitable width can be estimated except that we don't know the width of the row header. More difficult how to get the height of each row? Fitting uitable to an adhoc size is surely a classic question. Any idea?
Thanks a lot.
Alain
댓글 수: 0
채택된 답변
Abhishek Chakram
2023년 10월 6일
Hi Alain Barraud,
It is my understanding that you want to extend the “uitable” to the full width in a uifigure. To achieve this, you can use “uigridlayout”. Here is a sample code for the same:
% Create a uifigure
uifig = uifigure('Name', 'Table Example', 'Position', [100 100 400 300]);
% Create a uigridlayout
grid = uigridlayout(uifig);
grid.RowHeight = {'fit', '1x'}; % First row fits the table, second row takes the remaining space
% Create a uitable
uit = uitable(grid);
% Set the table data
data = magic(5);
uit.Data = data;
% Set the table layout within the grid
uit.Layout.Row = 1;
uit.Layout.Column = 1;
% Configure the grid layout
grid.ColumnWidth = {'1x'}; % Table takes the full width of the grid
grid.RowSpacing = 5; % Add some spacing between rows
% Display the uifigure
uifig.Visible = 'on';
In this example, the “uit” is placed inside the “grid”. The “uit” is then set to occupy the full width of the “uifig”.
You can refer to the following documentation to know more about the functions used:
Hope this answers your question.
Best Regards,
Abhishek Chakram
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!