• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JScrollpane Action Listener

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I am having two horizontal scollpanes in a frame.One on the left side and one on the right side.My requirement is that when i scroll the left hand side scrollpane ,the right hand side scrollpane should also scroll.Can someone tell me how to proceed.Thanks in advance

Regards
Ajay
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ajay Singh:
Hi all

I am having two horizontal scollpanes in a frame.One on the left side and one on the right side.My requirement is that when i scroll the left hand side scrollpane ,the right hand side scrollpane should also scroll.Can someone tell me how to proceed.Thanks in advance

Regards
Ajay




What have you got so far?
[HINT]
Think MVC and model.
You do NOT need to add or tweak any more listeners.
[ September 24, 2008: Message edited by: Maneesh Godbole ]
 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Actually i have got a SplitPane,left side i have put one panel having a scrollpane.

panelcontainer1.add(scrollPaneOne);
splitPane.setLeftComponent(panelcontainer1);

Likewise right side i have put another panel having a different scrollpane.

panelcontainer2.add(scrollPaneTwo);
splitPane.setRightComponent(panelcontainer2);

Before that scrollpane contains the JTable on both side.
( JScrollPane scrollPaneOne = new JScrollPane(jtableObj1);
JScrollPane scrollPaneTwo = new JScrollPane(jtableObj2)

Now when i scroll the left side scrollpane the right side scrollpane should also scroll,this is my requirement.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I understand how your UI is laid out.
My question was what have you tried out for the scrolling requirement?

Did you get my hint?
 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was putting like this

scrollPaneOne.addActionListener(ActionListener);,but there is no function like this for JScrollPane ,hence the question of how to do it or whether there is any other way around.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right idea, wrong listener.

You can't add the listener you need to the JScrollPane directly, but check getHorizontalScrollBar and getVerticalScrollBar. These return the actual JScrollBar instances that are used. Then check JScrollBar to see what kind of listeners you can add to those.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do it without listeners.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
scrollPaneOne.getVerticalScrollBar().setModel(scrollPaneTwo.getVerticalScrollBar().getModel());
 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manesh and Rob for the reply.I tried it now its working:-)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic