Results 1 to 12 of 12
Thread: JPanel
- 04-23-2010, 09:32 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
- 04-23-2010, 12:14 PM #2
-
If you have two scrollpanes that both hold JPanels that are the same size, you can get them to scroll in synchrony by having the vertical (or horizontal if that's the direction you're gearing at) JScrollBars share the same model, but mainly I second the recommendation that you post code as it's impossible to guess what your problem is based on the information you've provided so far.
- 04-23-2010, 07:35 PM #4
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
- 04-23-2010, 07:45 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 04-24-2010, 04:58 AM #6
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
It is easy to guess that you can simply connect the previous code to some simple modifications :)
Java Code:JScrollPane s1=new JScrollPane(); JScrollPane s2=new JScrollPane(); JScrollBar horizons1= s1.getHorizontalScrollBar(); JScrollBar horizons2=s2.getHorizontalScrollBar(); JScrollBar verticals1=s1.getVerticalScrollBar(); JScrollBar verticals2=s2.getVerticalScrollBar(); horizons2.setValue(horizons1.getValue()); verticals2.setValue(verticals1.getValue());
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
-
Last edited by Fubarable; 04-24-2010 at 05:01 AM.
- 04-24-2010, 05:23 AM #8
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Of course the code
is for JScrollBar action listener methodJava Code:horizons2.setValue(horizons1.getValue()); verticals2.setValue(verticals1.getValue());
it is also possible to use JScrollBar modelJava Code:AdjustmentListener adjustmentListener = new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) { horizons2.setValue(horizons1.getValue()); verticals2.setValue(verticals1.getValue()); } }; horizon1.addAdjustmentListener(adjustmentListener ); vertical1.addAdjustmentListener(adjustmentListener );
code like a
Java Code:s1.getVerticalScrollBar().setModel(s2.getVerticalScrollBar().getModel());
I recommend read some additional info
Scroll Control
and read some lessons lessonsIf my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
-
- 04-24-2010, 08:43 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
That ActionListener needs to be a mediator; it'd be a bit of convoluted code; but I agree that your suggestion of sharing a single model between the scroll bars is more elegant; WebUser's tip wasn't very thought out and no rep points although he keeps on begging for them ;-)
kind regards,
Jos
- 04-27-2010, 04:54 AM #11
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
- 04-27-2010, 05:16 AM #12
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Oh my... Author doesn't mean to use 4 JScrollPane - s, as I can remember ;)
Any JScrollPane contains 2 JScrollBars it is the fact )
you just add act. listeners to JScrollBar hor1 and JScrollBar ver1 (JScrollPane p1)
and then simply sinchronize their scrollers coordinates with JScrollBar hor2 and JScrollBar ver2 (JScrollPane p2). It is much easy :) The version I provide is supposed to use implementation. But the idea is identical )
Java Code:JScrollPane s1=new JScrollPane(); JScrollPane s2=new JScrollPane(); JScrollBar horizons1; JScrollBar horizons2; JScrollBar verticals1; JScrollBar verticals2; void initComp(){ horizons1= s1.getHorizontalScrollBar(); horizons2=s2.getHorizontalScrollBar(); verticals1=s1.getVerticalScrollBar(); verticals2=s2.getVerticalScrollBar(); horizon1.addAdjustmentListener(this); vertical1.addAdjustmentListener(this); } public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) { horizons2.setValue(horizons1.getValue()); verticals2.setValue(verticals1.getValue()); }Last edited by Webuser; 04-27-2010 at 05:38 AM.
If my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
Similar Threads
-
.add to a JPanel
By harrier in forum NetBeansReplies: 11Last Post: 07-13-2010, 10:24 AM -
image in jPanel
By idi in forum AWT / SwingReplies: 1Last Post: 03-13-2010, 09:30 PM -
I need some help with JPanel
By bantes in forum AWT / SwingReplies: 7Last Post: 11-03-2009, 07:58 PM -
drawing to a JPanel
By diggitydoggz in forum New To JavaReplies: 11Last Post: 03-09-2009, 07:42 AM -
How to use Jpanel
By Manfizy in forum NetBeansReplies: 0Last Post: 02-19-2009, 12:34 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks