Article View: borland.public.jbuilder.java.swing
Article #12316Re: Any way to keep two JScrollPanes in sync???
From: Matt Krevs
Date: Wed, 20 Jan 1999 00:00
Date: Wed, 20 Jan 1999 00:00
52 lines
2381 bytes
2381 bytes
I havent done this but... I think you may have to add a ChangeListener to the viewports of each table. When the user scrolls in either table the ChangeListener will be notified. Call getViewRect() to get the visible rectangle for the viewport that has just been scrolled Call scrollRectToVisible() on the other viewport to synchronise Kyle wrote in message ... >I'm using the example in chapter 16 of the book Java Swing by Robert >Eckstein that shows how to share two JTables with a common TableModel so >that the selections and such are reflected in the two different views. > >What is does not show is how to scroll in one JScrollPane and have the >other JScrollPane scroll along with it. > >Any ideas how to do this? > >Here is a snippit of what works so far... > > > JScrollPane jScrollPane1 = new JScrollPane(); > JTable jTable1 = new JTable(myTableModel, HeaderModel1); > JScrollPane jScrollPane2 = new JScrollPane(); > JTable jTable2 = new JTable(myTableModel, HeaderModel2); > JScrollPane jScrollPane3 = new JScrollPane(); > JTable jTable3 = new JTable(myTableModel, HeaderModel3); > > jScrollPane1.setColumnHeaderView(jTable1.getTableHeader()); > jScrollPane2.setColumnHeaderView(jTable2.getTableHeader()); > jScrollPane3.setColumnHeaderView(jTable3.getTableHeader()); > > jTable2.setSelectionModel(jTable1.getSelectionModel()); > jTable3.setSelectionModel(jTable1.getSelectionModel()); > > >Any ideas how to keep the scrolling in sync? > > >Thanks in advance... >Kyle > >P.S. I tried this and it did not work: > >jScrollPane2.getLayout(). >addLayoutComponent(ScrollPaneConstants.VERTICAL_SCROLLBAR, >jScrollPane1.getVerticalScrollBar()); > >jScrollPane3.getLayout().addLayoutComponent(ScrollPaneConstants.VERTICAL_ >SCROLLBAR, jScrollPane1.getVerticalScrollBar());
Technical Details
Message-ID:
<783cad$cf715@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<MPG.110ee1a1f1a8183d989692@forums.inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e33957ec48c6841 X-Google-Attributes: gid111d45,public From: "Matt Krevs" <mattkrevs@flex.com.au> Subject: Re: Any way to keep two JScrollPanes in sync??? Date: 1999/01/20 Message-ID: <783cad$cf715@forums.borland.com> X-Deja-AN: 434640518 References: <MPG.110ee1a1f1a8183d989692@forums.inprise.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing