Synchronize scroll bars of two uitables

13 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2012-8-25
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 个评论
Antoine Luijkx
Antoine Luijkx 2012-8-26
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

请先登录,再进行评论。

更多回答(1 个)

John Anderson
John Anderson 2018-6-20
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

类别

Help CenterFile Exchange 中查找有关 Desktop 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by