Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollpane Action Listener  RSS feed

 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • 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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it without listeners.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
scrollPaneOne.getVerticalScrollBar().setModel(scrollPaneTwo.getVerticalScrollBar().getModel());
 
Ajay Singh
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manesh and Rob for the reply.I tried it now its working:-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!