MATLAB: How to create a listbox with a scrollbar starting at the bottom of the listbox, when using GUIDE in MATLAB

barbottomboxguiguidelistlistboxlistboxtopMATLABscroll

How do I create a listbox with a scrollbar starting point at the bottom of a listbox, when using GUIDE in MATLAB?
I have a listbox in my GUI, and I would like the starting point of the scrollbar to be at the bottom of the list when the GUI is activated.

Best Answer

One way to have the scroll bar begin at the bottom of the Listbox is to set the 'Value' property of the Listbox to the number of elements in the list through the Property Inspector. The Property Inspector is a separate user interface that can be found as one of the menu items when right-clicking on the Listbox when designing the GUI. For example, if you have 6 elements choices in a list, setting the 'Value' property of the Listbox to '6' displays the starting point of the scroll bar at the bottom of the Listbox.
An alternative way to set the position of the scroll bar is to use the commands set(handles.listbox1,'Value',x) or set(handles.listbox1,'ListboxTop',x) in the Callback function, where x is the index of the last list item in the Listbox. For example,
set(handles.listbox1,'String',data); %populate the list with data
index = size(get(handles.listbox1,'string'), 1); %get how many items are in the list box
set(handles.listbox1,'ListboxTop',index); %set the index of last item to be the index of the top-most string displayed in list box.
or
set(handles.listbox1,'Value',index);
When setting the 'Value' parameter, the last element in the list gets highlighted. On the other hand, setting the 'ListboxTop' parameter does not highlight the last element in the Listbox.
Related Question