フィルターのクリア

Synchronize scroll bars of two uitables

9 ビュー (過去 30 日間)
Antoine Luijkx
Antoine Luijkx 2012 年 8 月 25 日
回答済み: John Anderson 2018 年 6 月 20 日
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 Center および File ExchangeJust for fun についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by