Is there a way to avoid scrollbars in an uitable?

Hi, I like to print some specific values beside a plot in an uitable und save it to a pdf. My uitable always creates scrollbars, so if I open the pdf I'm not able to see all values because I cannot scroll the bars anymore. I'm wondering if there is an option I can set to avoid the scrollbars and always get the fullsize of the uitable on my figure? Thanks for helping!

 Accepted Answer

I got an answer from matlab support and I want to share the solution with you: You can try to resize the uitable manually to its fullsize. When you define a uitable object it includes a property called 'Extent' which tells you exactly the size the table would need to have for it to come without scrollbars. After refering to the following example, I got the right behaviour:
f = figure; t = uitable(f,'Data',randi(100,10,3),'Position',[20 20 262 100]); t.Position(3:4) = t.Extent(3:4);

7 Comments

This code does not work for UIFigure. (R2019b)
>> f = uifigure; t = uitable(f,'Data',randi(100,10,3),'Position',[20 20 262 100]);
>> t.Extent(3:4)
ans =
0 0
Mike D.
Mike D. on 13 Sep 2020
Edited: Mike D. on 13 Sep 2020
Your second line showing "t.Extent(3:4)" should instead show "t.Position(3:4) = t.Extent(3:4)", which sets the position size equal to the extent size.
But yea I tried this for an app GUI using UIFigure and the Extent property is always [0, 0, 0, 0]. The only way I figured out how to remove the horizontal scroll bar is to keep increasing the Position(3) value until it disappears, but that's wider than I wanted.
No, for uifigure, Extent is all 0.
uitable created within uifigure have a different set of properties than uitable created within figure:
There does not appear to be anything equivalent to Extent for uitable within uifigure
I'm just trying to display a single column list of numbers in a UIFigure, that the user can edit and using uitable I need to make it width 110 before the horizontal scroll bar disappears. My numbers are all intergers and the widest/largest value is only about 1/3 the width of the column, and my column name is also only 1/3 the width. Not sure why Matlab chooses to make it so wide before horizontal scroll bar disappears. It would be nice if uitable could allow more control over the width of the columns.
I agree, for uitable within uifigure, the operation is not clear.
In the test I did, with numbers in the range +/- 9999, I needed width 132, at which point the widest number was at most half of the column width. Changing the font made very only a slight difference: with a very small font I could get it down to 131, but I also had to hit font sizes up to the 40's before triggered a scroll bar. There was also some hysterisis, with it requiring a wider width (up to 134) for a given large font size if I was controlling the width, but when I started with width 132 I was able to increase the font size through that same point, so the size requirements calculated when changing font size are not the same as the size requirements calculated when changing the width for a given font size.
Unfortunately it is all built-in methods, so we cannot examine them.
Mike D.
Mike D. on 17 Sep 2020
Edited: Mike D. on 17 Sep 2020
Arnav from tech support figured it out for me (for a UIFigure uitable). He said to set the position property width (for example 70), then set the column width to be about 20 less (50 pixels) to allow for the width of the vertical scroll bar. This will prevent a horizontal scroll bar. It works! My numbers are up to 220000 (six digits) taking up about 75% of the width of the column (not including the width of the vertical scroll bar). I'm using courier new font with size 10.
Amos
Amos on 24 Aug 2022
Edited: Amos on 24 Aug 2022
Seems rather clunky? Suggests perhaps that, besides 'auto' and 'fit', a third option ('fill'?) which allows designated column(s) to (exactly) partition the remaining width would save a lot of grief.
I note that trying to hide a one or more columns, by setting width(s) to zero, makes scrollbar avoidance even less intuitive (if it's possible at all). Perhaps I was seeing hysterisis analogous to that suggested by @Walter Roberson above.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Asked:

on 12 Sep 2018

Edited:

on 24 Aug 2022

Community Treasure Hunt

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

Start Hunting!