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

采纳的回答

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