Synchronize scroll bars of two uitables

23 views (last 30 days)
Hello,
In a GUI, I created two (large) uitables. I need to synchronize scrollbars (horizontal and vertical), so when the user browses (scrolls down, up, left, right...) in one uitable, the view of the other uitable follows and keeps synchronized (same rows/columns are shown).
Is there a way to do that?
Thank you,
Antoine

Accepted Answer

Walter Roberson
Walter Roberson on 25 Aug 2012
There is no documented way to affect the scrolling of even one uitable.
You may be able to work at the Java level; see http://undocumentedmatlab.com/
  1 Comment
Antoine Luijkx
Antoine Luijkx on 26 Aug 2012
Thanks Walter. Indeed, that's what I feared.
I built up some code based on the Java level (see below). However, I have visual bugs after uitable update and I have to refresh manually the uitables.
Moreover, it works well when navigating through uitables with mouse-clicking on scroll bars, but when I try to navigate with keyboard (right, left, page down, etc...), that becomes messy, because the selected cell goes from one uitable to the other one.
Finally, I have to use try/cach, because I receive some java errors (Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException)
Any thought on this?
function temp_to_delete()
figure(1);
tab1 = uitable('Parent',gcf,'Data',magic(400),'Units','normalized','Position',[.05 .2 .4 .4]);
tab2 = uitable('Parent',gcf,'Data',magic(400),'Units','normalized','Position',[.55 .2 .4 .4]);
jhEdit1 = findjobj(tab1);
jhEdit2 = findjobj(tab2);
set(jhEdit1,'AdjustmentValueChangedCallback',{@slider_callback});
set(jhEdit2,'AdjustmentValueChangedCallback',{@slider_callback});
function slider_callback(~,e)
try
val=get(get(e,'Source'),'Value');
if get(e,'Source')== get(jhEdit1,'HorizontalScrollBar')
set(get(jhEdit2,'HorizontalScrollBar'),'Value',val);
set(tab2,'Visible','off');pause(0.01);set(tab2,'Visible','on');
elseif get(e,'Source')== get(jhEdit1,'VerticalScrollBar')
set(get(jhEdit2,'VerticalScrollBar'),'Value',val);
set(tab2,'Visible','off');pause(0.01);set(tab2,'Visible','on');
elseif get(e,'Source')== get(jhEdit2,'HorizontalScrollBar')
set(get(jhEdit1,'HorizontalScrollBar'),'Value',val);
set(tab1,'Visible','off');pause(0.01);set(tab1,'Visible','on');
elseif get(e,'Source')== get(jhEdit2,'VerticalScrollBar')
set(get(jhEdit1,'VerticalScrollBar'),'Value',val);
set(tab1,'Visible','off');pause(0.01);set(tab1,'Visible','on');
end
catch
end
end
end
Thanks again,
Antoine

Sign in to comment.

More Answers (1)

John Anderson
John Anderson on 20 Jun 2018
Thanks for this answer, very useful. There may well be better ways of doing this now. However, to avoid having to play around with the visibility of the matlab uitable objects using the lines
set(tab1,'Visible','off');pause(0.01);set(tab1,'Visible','on');
you can simply invoke the repaint method of the javacomponent. This reduces the flicker and makes the operation run a little smoother.
jhEdit2.repaint
jhEdit1.repaint

Categories

Find more on Just for fun in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!