Resize uable in matlab

I am using uitable in Matlab GUI. In this GUI, rows and columns can be after every processing, so I cannot use the Position property for uitable. when I draw a table, some area remains empty and its position is also always in the bottom left layer of the GUI. The image is shown below:

enter image description here

I want to remove the white area from the table. The table automatically resizes to fit the row and columns.

How can i do this?

+3


source to share


1 answer


Possible way to solve this problem: row height and column width are not related to table dimensions, as a table can contain any number of rows / columns. This is why the table has scroll bars. For this reason, resizing the table only affects the so-called scroll view screen and does not affect any internal aspect such as row height or column width. You can catch the resize callback and programmatically change the row height and column width based on the new table size. However, I suggest NOT to do this because most of the users are used for the current behavior, not only in Matlab, but in most GUI based applications.

Another possible way is if you normalize your units using "FontUnits", "Normalized" it might help you. As the font size changes, so will the row and column widths, but the moment the font does not need to expand the column width, the column will stop resizing.



The following code will serve the purpose.

clear all;
clc;

%% Create a random dataset with any number of rows and columns
data = rand(10, 15);

%% Create a uitable
t = uitable('Data',data);

%% Set the position and size of UITable
% Position(1) = Distance from the inner left edge of the figure
% Position(2) = Distance from the inner bottom edge of the figure
% Position(3) = Distance between the right and left edges of  rectangle containing the uitable
% Position(4) = Distance between the top and bottom edges of  rectangle containing the uitable
% Extent(1) = Always zero
% Extent(2) = Always zero
% Extent(3) = Width of uitable
% Extent(4) = Height of uitable
t.Position = [350 350 t.Extent(3) t.Extent(4)];

%%End

      

+3


source







All Articles