Uitable gui different size on different computers

1 view (last 30 days)
I have a table of data in my gui that displays fine and where I want it to be. However when run on a different machine, the table itself is in the same place, but the data does not fill the table and there is a white edge around it.
Here is the code for the table and an image of what I mean with the white edge.
The problem appears to be the width of the first column. It is of a different size on separate computers. Any idea how I can set this to be the same? There does not appear to be a variable I can change for it? Thanks.
tonetable = uitable(main_window, 'data', finaldata);
tonetable.ColumnName = {'Value'} ;
tonetable.BackgroundColor = [.4 .4 .4; 1 0.5 0];
tonetable.ForegroundColor = [1 1 1];
tonetable.RowName = {'-----'};
tonetable.Position = [875 85 350 330];
tonetable.ColumnWidth = {128};
tonetable.FontSize = 10;

Accepted Answer

Cam Salzberger
Cam Salzberger on 16 May 2017
Edited: Cam Salzberger on 16 May 2017
Hello James,
Different systems, especially if they have different operating systems, will frequently cause UI components to appear in different sizes. Using 'Position' units of all 'character' can help to make sure any changes scale with the system, and still fit the text contents of the component.
However, for this particular issue, I think there's a much simpler workaround. If you just specify the 'ColumnWidth' property to 'auto', rather than providing an exact value, I believe that they will fill the table, and should fit the text if it is possible to do so. You could even specify the width of one of the columns exactly, and let the other one be 'auto' so that it can grow or shrink to fill the table as necessary. See the examples in the documentation page for both methods.
-Cam
  1 Comment
James Boyle
James Boyle on 17 May 2017
Thanks for the answer Cam. The simple solution did not work, as it did not fit to the space I wanted it (I want it to be the same size as a graph next to it). I think I've found a solution however by finding the size of the screen and then scaling the table size to it, meaning it should appear the same regardless of screen resolution etc: Example:
screen_size = get(0,'screensize');
screen_width = screen_size(3);
width_scale = 302/2560;
table_width = width_scale * screen_width;

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!