Newsgroup: it.comp.java
Titolo: setScrollPosition!!!!

Come funziona il metodo setScrollPosition di uno Scrollpane ?


guarda queste 2 FAQ, le ho trovati sul sito della sun mentre cercavo esempi
su setvadjustable (la funzione search è molto utile, ho scoperto)
ciao
frolix8
A way to link ScrollPanes?
11-jan-99 : 11:22 :vrsix
Jdk1.1.5, Solaris, stand-alone app.
I want to have three ScrollPanes, but only one of them with visible
scrollbars, we'll call this ScrollPane the Master ScrollPane. I also want to
have two other ScrollPanes without visible scrollbars, we'll call these
Slave1 and Slave2.
When Main's horizontal scrollbar is adjusted, I want to scroll Slave1
horizontally the EXACT same amount. Similary, when Main's vertical scrollbar
is adjusted, I want to scroll Slave2 vertically the exact same amount.
Is it possible to add additional adjustment listeners to Main's scrollbars
to catch the adjustments and then set Slave1 and Slave2 accordingly? It
seems possible since I can get the Adjustment objects from Main's
scrollbars, but I just wanted to run this by you folks first.
Thanks (again!).. 
vr...@eudoramail.com
----------------------------------------------------------------------------
----
12-jan-99
15:18
daney       (#1 of 3) Add New Message
 It will work.
----------------------------------------------------------------------------
----
13-jan-99
13:47
cs_cpc       (#2 of 3) Add New Message
 Use getVAdjustable() and getHAdjustable() to get the Adjustable objects of
the scrollbars. Add adjustment listeners to each. On the
adjustmentValueChanged() of one, call Slave1.setScrollPosition() On the
adjustmentValueChanged() of the other, call Slave2.setScrollPosition(). Use
the AdjustmentEvent in each listener to getValue() of the change. Use the
getAdjustable() to access any other information about the scrollbar.
You may want to turn the value into a Percent so that it has the same
proportional meaning to Master and Slave Scrollbars. Example
file://Uncompiled, Unproven, Untested // public void
adjustmenetValueChanged(AdjustmentEvent e) { Adjustable a = getAdjustable();
double d = (double)e.getValue() / (double)a.getMaximum();
Adjustable b = Slave1.getHAdjustable(); Adjustable c =
Slave1.getVAdjustable(); Slave1.setScrollPosition( b.getValue(),
c.getMaximum() * d); }
The idea is to get the event value, turn it into a percent and then adjust
on of the Slaves scrollbars to the same percent (c.getMaximum() * d).
You may wish to define some of the classes as inner classes so that Slave1
and Slave2 objects are accessable by the AdjustmentListeners.
****************************************************************************
*************************
setScrollPosition() not working in applet
15-dec-99 : 8:49 :grandpoobahscott
I have an applet which highlights a location on a map; If the location is
outside the viewport, I want to scroll to a point 50 pixels less than X and
Y of the location.
        ScrollPane SP = new ScrollPane();
        MapCanvas MC = new MapCanvas();
        MC.setSize(W,H);
        SP.add(MC);
        SP.setSize(620,470);
        Point newLoc = new Point(Xparm - 50,Yparm - 50);
        SP.setScrollPosition(newLoc);
I have also tried "setScrollPosition(Xparm,Yparm)" to no effect. This does
not work; anybody know what is wrong?
----------------------------------------------------------------------------
----
28-feb-00
13:59
pilot11       (#1 of 1) Add New Message
 I had the same problem and found that placing the setScrollPosition() code
in the paint() function solved the problem. setScrollPosition() does not
seem to work until after returning from initialization code. Anyone know
what to call to make this work during initialization? DoLayout() sets the
min and max values for the Adjustment controls correctly but
setScrollPosition() still does not work. The paint() hack works for now.