Search code examples
matlabmatlab-figurematlab-guidematlab-uitable

MATLAB - uitable scrollbar visibility


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.


Solution

  • 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)