Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2006

Tip: Looking for answers? Try searching our database.

Design Issue - Any way to Sych 2 JScrollPanes - so they scroll as one ?..

Thread view: 
Bill - 30 Mar 2006 12:47 GMT
Hi All,
   I need a display where the left portion is fixed, and the right portion
can be scrolled horizontally.

   But they both need to scroll vertically and be kept in synch. Any
idea's?

TIA

Bill

Left Side    Right Side
AAAAA    111111111111111111111111111111111111111111
BBBBB    2222222222222222222222222222222222222222222
CCCCC    3333333333333333333333333333333333333333333
DDDDD   444444444444444444444444444444444444444444
EEEEE      555555555555555555555555555555555555555555

The 'right side' is too wide too fit on a screen so it needs to scoll
horizontally

But they both need to scroll vertically and be kept 'in synch' so AAAA is
always aligned with
1111111 etc
Thomas Fritsch - 30 Mar 2006 14:04 GMT
> I need a display where the left portion is fixed, and the right portion
> can be scrolled horizontally.
>
> But they both need to scroll vertically and be kept in synch. Any
> idea's?
[I once had a similar problem, when I wanted to display a large table of
65536 characters (16 columns, 4096 rows) in a scrollpane.]

> Left Side    Right Side
> AAAAA    111111111111111111111111111111111111111111
[quoted text clipped - 9 lines]
> always aligned with
> 1111111 etc

Don't use 2 scrollpanes. Use only 1 scrollpane, and set a 1-column-table
 as the row-header of the scrollpane. Assure that both tables have the
same row height. Then the scrollpane kindly keeps your 2 tables in sync.
You do the setup roughly like this:

  JTable mainTable = new JTable(...); // table with k columns, n rows,
  JTable rowHeader = new JTable(...); // table with 1 column, n rows
  // You'll probably need 2 different table models, one for each table

  JScrollPane scrollPane = new JScrollPane(mainTable);
  scrollPane.setRowHeaderView(rowHeader);

  scrollPane.setHorizontalScrollbarPolicy(...);
  scrollPane.setVerticalScrollbarPolicy(...);
  // and because you want the horizontal scrollbar:
  mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

IchBin - 30 Mar 2006 15:41 GMT
> Hi All,
>     I need a display where the left portion is fixed, and the right portion
[quoted text clipped - 20 lines]
> always aligned with
> 1111111 etc

You did not mention what objects are in the scroll panes.

I found this out in the newsgroups:

"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 synchronize"

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
Bill - 31 Mar 2006 00:40 GMT
Hi All,

   the left side is a vertival line of JLabels

   the right side is a chart represented by a series of JLabels

   Each label represents an event. (a mainframe batch job).

   So the chart on the right would have JLabels positioned to represent the
time of night they ran, and their width would be somewhat proportional to
their elapsed time.

TIA

Bill

>> Hi All,
>>     I need a display where the left portion is fixed, and the right
[quoted text clipped - 38 lines]
> 'If there is one, Knowledge is the "Fountain of Youth"'
> -William E. Taylor,  Regular Guy (1952-)
Michael Dunn - 30 Mar 2006 19:17 GMT
> Hi All,
>    I need a display where the left portion is fixed, and the right portion can be scrolled
[quoted text clipped - 17 lines]
> But they both need to scroll vertically and be kept 'in synch' so AAAA is always aligned with
> 1111111 etc

For horizontal, just set the respective policies.
For vertical scrolling in synch, set the scrollbar models the same
simple demo:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Testing extends JFrame
{
 public Testing()
 {
   JScrollPane sp1 = new JScrollPane(new ScrollPanel());
   JScrollBar sBar1 = sp1.getVerticalScrollBar();
   JScrollPane sp2 = new JScrollPane(new ScrollPanel());
   JScrollBar sBar2 = sp2.getVerticalScrollBar();
   sBar2.setModel(sBar1.getModel()); //<--------------synchronize
   getContentPane().setLayout(new GridLayout(1,2));
   getContentPane().add(sp1);
   getContentPane().add(sp2);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setSize(400,300);
   setLocation(400,300);
 }
 public static void main(String[] args) {new Testing().setVisible(true);}
}
class ScrollPanel extends JPanel
{
 public ScrollPanel()
 {
   setLayout(new GridLayout(50,1));
   for(int x = 0; x < 50; x++) add(new JLabel(""+(x+1)));
 }
}
Bill - 31 Mar 2006 00:41 GMT
Thanks for all you suggestions, I'll give them a try.

Bill

>> Hi All,
>>    I need a display where the left portion is fixed, and the right
[quoted text clipped - 55 lines]
>  }
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.