how to get uitable extent within uifigure

조회 수: 14 (최근 30일)
Alain Barraud
Alain Barraud 2022년 4월 16일
댓글: Alain Barraud 2023년 10월 6일
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

채택된 답변

Abhishek Chakram
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
  댓글 수: 1
Alain Barraud
Alain Barraud 2023년 10월 6일
Hi
I have never used uigridlayout probably because I have not well understood its utility.
Yes your example answers to my question.
Once executed, horizontal and vertical scrolling bars appear as expected and disappears if I increase the uifigure width with my mouse. Curiously if now I decrease the uifigure height the uitable disappears progressively without any vertical scrolling bar. Any idea?
Best regards
Alain

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by