Naseeb Gill
Naseeb Gill

Reputation: 661

Change size of uitable in matlab

I am using uitable in matlab GUI. In this GUI, rows and columns of uitable after each processing and hence I can't use Position property of uitable. when I draw table some area remain blank and its position is also always in left lower cornser of GUI figure. Image is shown below:

enter image description here

I want to remove white area from table i.e table automatically resize itself according to row and columns.

How I can do this?

Upvotes: 3

Views: 6174

Answers (1)

Waseem Anwar
Waseem Anwar

Reputation: 301

A possible way-around to handle this issue: uitable row height and column width are unrelated to the table's dimensions, since a table can contain any number of rows/cols. This is why the table has scrollbars. For this reason, resizing the table only affects the so-called scrollbars viewport, and does NOT affect any internal aspect such as row height or column width. You can trap the resizing callback and programmatically modify the row height and column width depending on the new table size. However, I suggest to NOT do this because most users are used to the current behavior, not just in Matlab but in most GUI-based applications.

Another possible way-around can be if you normalize your units, using 'FontUnits', 'Normalized', it may help you. Since Font size will change, also will your row and column width, but the moment the font does not need to expand column width, column will stop re-sizing.

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

Upvotes: 3

Related Questions