how to get uitable extent within uifigure

12 visualizaciones (últimos 30 días)
Alain Barraud
Alain Barraud el 16 de Abr. de 2022
Comentada: Alain Barraud el 6 de Oct. de 2023
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

Respuesta aceptada

Abhishek Chakram
Abhishek Chakram el 6 de Oct. de 2023
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 comentario
Alain Barraud
Alain Barraud el 6 de Oct. de 2023
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by