-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
None
-
5.0
-
sparc
-
solaris_2.6
Name: sdR10048 Date: 05/18/2004
Filed By : SPB JCK team (###@###.###)
JDK : build 1.5.0-beta2-b51
Platform[s] : Solaris
Specification excerpt:
======================
--------- J2SE API spec v.1.5 ---------
...
java.awt.ScrollPane:
==================
public void setScrollPosition(Point p)
Scrolls to the specified position within the child component. A call to this method is only valid if the scroll pane contains a child and the specified position is within legal scrolling bounds of the child. Specifying a position outside of the legal scrolling bounds of the child will scroll to the closest legal position. Legal bounds are defined to be the rectangle: x = 0, y = 0, width = (child width - view port width), height = (child height - view port height). This is a convenience method which interfaces with the Adjustable objects which represent the state of the scrollbars.
Parameters:
p - the Point representing the position to scroll to
java.awt.ScrollPane:
==================
public Point getScrollPosition()
Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port. This is a convenience method which interfaces with the adjustable objects which represent the state of the scrollbars.
Returns:
the coordinate position for the current scroll position
Throws:
NullPointerException - if the scrollpane does not contain a child
java.awt.Toolkit
==============
Many GUI operations may be performed asynchronously. This means that if you set the state of a component, and then immediately query the state, the returned value may not yet reflect the requested change. This includes, but is not limited to:
Scrolling to a specified position.
For example, calling ScrollPane.setScrollPosition and then getScrollPosition may return an incorrect value if the original request has not yet been processed.
...
---------- end-of-excerpt ---------------
Problem description
===================
Sometimes the method
java.awt.ScrollPane.getScrollPosition()
returns the wrong position, not just the one that has been set before.
"Sometimes" means if we call setScrollPosition multiple times in rapid succession.
Please see the demo.
Note that this is an intermittently error -- thus may be you'll have to run this demo
several times to reproduce it. Please use the Solaris platform, I couldn't reproduce
it under the Linux.
May be it will be interesting: please note the output of the getScrollPosition() in the demo's output: java.awt.Point[x=12,y=11]
Not java.awt.Point[x=11,y=11] or java.awt.Point[x=10,y=10]...
Minimized test:
===============
------- J.java -------
import java.awt.*;
public class J {
public static void main(String[] args) {
// some GUI preparatory stuff
Frame frame = new Frame();
frame.setBounds(100, 100, 300, 300);
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Canvas canvas = new Canvas();
canvas.setSize(500, 500);
sp.add(canvas);
frame.add("Center", sp);
frame.setVisible(true);
// the test itself
for (int i=1; i<100; i++) {
Point p = new Point(i, i);
sp.setScrollPosition(p);
// waiting till the next scroll position "arrives"
while ( !p.equals(sp.getScrollPosition()) ) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
System.exit(1);
}
System.out.println("set position : "+p);
System.out.println("get position : "+sp.getScrollPosition());
System.out.println("waiting...");
}
}
frame.dispose();
System.out.println("PASSED");
}
}
------- end-of-J.java -------
Minimized test output:
======================
] (18:06:17) dsv@orion ~/tmp
] java -showversion J
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Server VM (build 1.5.0-beta2-b51, mixed mode)
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
^C
======================================================================
Filed By : SPB JCK team (###@###.###)
JDK : build 1.5.0-beta2-b51
Platform[s] : Solaris
Specification excerpt:
======================
--------- J2SE API spec v.1.5 ---------
...
java.awt.ScrollPane:
==================
public void setScrollPosition(Point p)
Scrolls to the specified position within the child component. A call to this method is only valid if the scroll pane contains a child and the specified position is within legal scrolling bounds of the child. Specifying a position outside of the legal scrolling bounds of the child will scroll to the closest legal position. Legal bounds are defined to be the rectangle: x = 0, y = 0, width = (child width - view port width), height = (child height - view port height). This is a convenience method which interfaces with the Adjustable objects which represent the state of the scrollbars.
Parameters:
p - the Point representing the position to scroll to
java.awt.ScrollPane:
==================
public Point getScrollPosition()
Returns the current x,y position within the child which is displayed at the 0,0 location of the scrolled panel's view port. This is a convenience method which interfaces with the adjustable objects which represent the state of the scrollbars.
Returns:
the coordinate position for the current scroll position
Throws:
NullPointerException - if the scrollpane does not contain a child
java.awt.Toolkit
==============
Many GUI operations may be performed asynchronously. This means that if you set the state of a component, and then immediately query the state, the returned value may not yet reflect the requested change. This includes, but is not limited to:
Scrolling to a specified position.
For example, calling ScrollPane.setScrollPosition and then getScrollPosition may return an incorrect value if the original request has not yet been processed.
...
---------- end-of-excerpt ---------------
Problem description
===================
Sometimes the method
java.awt.ScrollPane.getScrollPosition()
returns the wrong position, not just the one that has been set before.
"Sometimes" means if we call setScrollPosition multiple times in rapid succession.
Please see the demo.
Note that this is an intermittently error -- thus may be you'll have to run this demo
several times to reproduce it. Please use the Solaris platform, I couldn't reproduce
it under the Linux.
May be it will be interesting: please note the output of the getScrollPosition() in the demo's output: java.awt.Point[x=12,y=11]
Not java.awt.Point[x=11,y=11] or java.awt.Point[x=10,y=10]...
Minimized test:
===============
------- J.java -------
import java.awt.*;
public class J {
public static void main(String[] args) {
// some GUI preparatory stuff
Frame frame = new Frame();
frame.setBounds(100, 100, 300, 300);
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Canvas canvas = new Canvas();
canvas.setSize(500, 500);
sp.add(canvas);
frame.add("Center", sp);
frame.setVisible(true);
// the test itself
for (int i=1; i<100; i++) {
Point p = new Point(i, i);
sp.setScrollPosition(p);
// waiting till the next scroll position "arrives"
while ( !p.equals(sp.getScrollPosition()) ) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
System.exit(1);
}
System.out.println("set position : "+p);
System.out.println("get position : "+sp.getScrollPosition());
System.out.println("waiting...");
}
}
frame.dispose();
System.out.println("PASSED");
}
}
------- end-of-J.java -------
Minimized test output:
======================
] (18:06:17) dsv@orion ~/tmp
] java -showversion J
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Server VM (build 1.5.0-beta2-b51, mixed mode)
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
set position : java.awt.Point[x=12,y=12]
get position : java.awt.Point[x=12,y=11]
waiting...
^C
======================================================================
- relates to
-
JDK-6466675 api/java_awt/ScrollPane/descriptions.html#sets doesn't work correctly on windows.
- Closed
-
JDK-6404832 scrolling and resize problem in Window XP
- Closed
-
JDK-4008152 scrollPane.setScrollPosition() does not always result in correct values
- Closed