0

Is it possible to set the visibility of a Matlab uitable vertical scrollbar to display at all times, and if so, how?

When the table's row height * number of rows is less than the total uitable height, no scroll bar is displayed, and there is 'empty' space to the right of the table where the vertical scroll bar would be. This is not appealing to look at, and I would like to show the scrollbar at all times there.

I have read this page, http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars however it has not been helpful for the uitable scrollbars.

eNc
  • 1,021
  • 10
  • 23

1 Answers1

1

Using Yair's findjobj tool, I'm able to do this using VERTICAL_SCROLLBAR_ALWAYS for the VerticalScrollBarPolicy.

table = uitable();
jtable = findjobj(table);

policy = javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;

set(jtable, 'VerticalScrollBarPolicy', policy)

enter image description here

This blog post claims that you have to setup a callback for when the uitable is resized, but I haven't seen any issues without doing that on R2015b. But for the sake of completeness

 callback = @(s,e)set(s, 'VerticalScrollBarPolicy', policy);
 set(jtable, 'ComponentResizedCallback', callback)
Suever
  • 64,497
  • 14
  • 82
  • 101
  • Based on this answer I was able to figure out that I missed the import statement when I was trying Yair's tool, and it was breaking the code. Thanks! – eNc Mar 05 '16 at 22:00
  • @eNc The import statement is actually optional. I just did it so that I could fit the code in a narrow window. You could also use the full name of the constant `javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS` rather than importaing anything – Suever Mar 05 '16 at 22:01
  • That's even better, makes for cleaner code in my case. Thanks a bunch! – eNc Mar 05 '16 at 22:02