MATLAB: How to control Uitable scroller position

findjobjMATLABMATLAB Compiler SDKscrollbaruitable

Hi,
when an uitable is updated, uitable automatically resets to focus on the top row of data.
Is there a way to set the scroll position in the table instead of "jumping" every time the table is updated?
Thankyou for your time…
Regards, Sainath M.

Best Answer

This workaround solution use again the FEX: findjobj functionality and implicitly sets the selection mode to SINGLE_SELECTION. If the user selects a new cell, then the focus is switched to the view making the selected row now visible again.
set(mtable, 'CellSelectionCallBack', @selectionChangeCallBack);
function selectionChangeCallBack(src, eventdata)
if ~isempty( eventdata.Indices)
where_changed = eventdata.Indices(1);
jscrollpane = javaObjectEDT(findjobj(src));
viewport = javaObjectEDT(jscrollpane.getViewport);
jtable = javaObjectEDT( viewport.getView );
jtable.scrollRowToVisible(where_changed - 1);
end
end
it requires findjobj functionality, and works fine on Matlab R2017a.