JDK-4008152 : scrollPane.setScrollPosition() does not always result in correct values
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.0,1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_2.5
  • CPU: generic,sparc
  • Submitted: 1996-10-09
  • Updated: 2004-03-20
  • Resolved: 2003-08-27
Related Reports
Duplicate :  
Relates :  
Description
In the following sequence:

scrollPane.setScrollPosition(0,0);
Point pt = scrollPane.getScrollPosition();

does not leave pt as 0,0.

It isn't clear what the side effects of this are on hotjava, but it may
be the cause of some scrolling and repainting bugs.


--------------------------------- Reopen -----------------------------
Here is the example demonstrating the bug:

----------------Test.java---------------------
import java.awt.*;

public class Test {
    public static void main(String [] args) {
        Point p;
	Frame frame = new Frame();
	frame.setBounds(100,100,100,100);
	ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
	Canvas canvas = new Canvas();
	canvas.setSize(300,300);
	sp.add(canvas);
	frame.add("Center",sp);
	frame.setVisible(true);
	
	for (int i=0;i<1000;i++) {
	    p = new Point(i%100,i%100);
	    sp.setScrollPosition(p);
	    if (!sp.getScrollPosition().equals(p)) {
	        System.out.println("Test Failed.");
	        System.out.println(i+" : Expected "+p+", but Returned: "+sp.getScrollPosition());
	        frame.dispose();
		System.exit(0);
            }
        } 
	System.out.println("Test Passed."); 
	frame.dispose();             
    }
}

-- The output ----------------
#>java Test
Test Failed.
15 : Expected java.awt.Point[x=15,y=15], but Returned: java.awt.Point[x=12,y=15
------------------------------

###@###.### 1998-01-23

Comments
EVALUATION [jeff.dinkins@Eng 1996-11-15] John - this is a bug on Solaris/motif only, correct? ------ [from John Pampuch 1996-11-15] Yes, as far as I can tell, it is a solaris/motif only problem. I was unable to duplicate it under solaris/tiny, and at the time, I couldn't test under Windows. xianfa.deng@Eng 1997-11-25 I used the following test code to run on Solaris in JDK.1.5, the getScrollPosition() returns non (0,0). So the problem is not reproducible in JDK1.1.4. // test case for getScrollPosition() import java.awt.*; import java.awt.event.*; public class MyFrame extends Frame { ScrollPane pane; class comp extends Component { public comp(){} public Dimension getPreferredSize() { return new Dimension(400,400); } } class AdjustmentAdapter implements AdjustmentListener { public void adjustmentValueChanged(AdjustmentEvent e){} } AdjustmentAdapter adjustmentListener = new AdjustmentAdapter () { /** * Scrolls the column or row header depending on which scrollbar * in the scrollPane was clicked */ public void adjustmentValueChanged(AdjustmentEvent e) { if (e.getAdjustmentType() == AdjustmentEvent.BLOCK_DECREMENT) System.out.println("BLOCK_DECREMENT"); else if (e.getAdjustmentType() == AdjustmentEvent.BLOCK_INCREMENT) System.out.println("BLOCK_INCREMENT"); else if (e.getAdjustmentType() == AdjustmentEvent.UNIT_DECREMENT) System.out.println("UNIT_DECREMENT"); else if (e.getAdjustmentType() == AdjustmentEvent.UNIT_INCREMENT) System.out.println("UNIT_INCREMENT"); else if (e.getAdjustmentType() == AdjustmentEvent.TRACK) { // pane.setScrollPosition(10,10); Point pt = pane.getScrollPosition(); System.out.println("TRACK " + pt); } } }; public MyFrame() { super(); add(pane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED)); pane.add(new comp()); pane.getHAdjustable().setBlockIncrement(10); pane.getHAdjustable().addAdjustmentListener(adjustmentListener); pane.getVAdjustable().addAdjustmentListener(adjustmentListener); } public static void main(String [] args) { MyFrame f = new MyFrame(); f.setSize(200,200); f.setVisible(true); } } ----------------------------------- I have to reopen this bug because Vladimir Sizikov, vvs@russia has new test code that shows bug in setScrollPosition(). JDK1.1.6, JDK12beta3 ###@###.### 1998-01-23 ------------------------------------------------------------ I tested this on Sun4 Solaris 2.6 with JDK 1.1.8. Since there has been no development on this, and I suppose the test case that reproduced the issue under JDK 1.1.6/1.2beta3 is not attached, this bug report can be closed. sandeep.konchady@Eng 1999-11-15 ###@###.### 1999-11-22 Test case is included to this bugreport (Test.java) fails under JDK1.1.8 JDK1.2 and JDK1.3. JCK tests api/java_awt/ScrollPane/descriptions.html#gets api/java_awt/ScrollPane/descriptions.html#sets are excluded from test suite with this bug id. We cannot unexclude tests that fail from time to time, so we should reopen this bug. Here is output of Test.java: <sda@spear(pts/1).484> uname -a SunOS spear 5.6 Generic_105181-16 sun4u sparc SUNW,Ultra-1 <sda@spear(pts/8).559> java -showversion Test java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-O) Java HotSpot(TM) Client VM (build 1.3-O, interpreted mode) Warning: Cannot allocate colormap entry for default background Test Failed. 59 : Expected java.awt.Point[x=59,y=59], but Returned: java.awt.Point[x=8,y=7] <sda@spear(pts/18).280> /set/java/jdk1.1.8/solaris/bin/java -fullversion java full version "JDK1.1.8M" <sda@spear(pts/18).282> /set/java/jdk1.1.8/solaris/bin/java Test Warning: Cannot allocate colormap entry for default background Warning: Name: VertScrollBar Class: XmScrollBar The specified scrollbar value is less than the minimum scroll bar value. Test Failed. 41 : Expected java.awt.Point[x=41,y=41], but Returned: java.awt.Point[x=40,y=41] <sda@mozart(pts/3).271> uname -a SunOS mozart 5.7 Generic_Patch sun4u sparc SUNW,Ultra-5_10 <sda@mozart(pts/3).275> /set/java/jdk1.2/solaris/bin/java Test Warning: Cannot allocate colormap entry for default background Warning: Name: VertScrollBar Class: XmScrollBar The specified scrollbar value is less than the minimum scroll bar value. Warning: Name: VertScrollBar Class: XmScrollBar The specified scrollbar value is less than the minimum scroll bar value. Test Failed. 2 : Expected java.awt.Point[x=2,y=2], but Returned: java.awt.Point[x=1,y=1] The bug was reproducible in 1.3.1 but not in 1.4. Closing out as will not fix. I would suggest an upgrade or an escalation to fix this problem. michael.martak@Eng 2001-07-10 -------- JCK-runtime-14 test api/java_awt/ScrollPane/descriptions.html#sets still fails under build 1.4.0-beta_refresh-b73 due to this bug: %java -version java -version java version "1.4.0-beta_refresh" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b73) Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b73, mixed mode) %java javasoft/sqe/tests/api/java/awt/ScrollPane/setsTests ScrollPane0400: Passed. OKAY ScrollPane0401: Passed. OKAY ScrollPane0402: Passed. OKAY ScrollPane0403: Passed. OKAY ScrollPane0404: Passed. OKAY ScrollPane0405: Passed. OKAY ScrollPane0406: Failed. Expected java.awt.Point[x=131,y=153], but returned: java.awt.Point[x=129,y=146] ScrollPane0407: Passed. OKAY ScrollPane0408: Passed. OKAY ScrollPane0409: Passed. OKAY ScrollPane0410: Passed. OKAY ScrollPane0411: Passed. OKAY ScrollPane0412: Failed. Expected java.awt.Point[x=131,y=153], but returned: java.awt.Point[x=129,y=146] ScrollPane0413: Passed. OKAY ScrollPane0414: Passed. OKAY ScrollPane0415: Passed. OKAY ScrollPane0416: Passed. OKAY ====== ScrollPane0400 ====== ====== ScrollPane0401 ====== ====== ScrollPane0402 ====== ====== ScrollPane0403 ====== ====== ScrollPane0404 ====== ====== ScrollPane0405 ====== ====== ScrollPane0406 ====== ====== ScrollPane0407 ====== ====== ScrollPane0408 ====== ====== ScrollPane0409 ====== ====== ScrollPane0410 ====== ====== ScrollPane0411 ====== ====== ScrollPane0412 ====== ====== ScrollPane0413 ====== ====== ScrollPane0414 ====== ====== ScrollPane0415 ====== ====== ScrollPane0416 ====== STATUS:Failed.tests: 17; passed: 15; failed: 2; first test case failure: ScrollPane0406 Additional information: $uname -a SunOS sword 5.8 Generic_108528-06 sun4u sparc SUNW,Ultra-2 %echo $DISPLAY sword:0.0 ###@###.### 2001-08-03 Commit to fix in Hopper (JCK-exclude list). ###@###.### 2001-12-02 I wonder if the problem is just the asynchronicity of events on X? ###@###.### 2002-10-01 Name: dmR10075 Date: 08/21/2003 The test passes with both XAWT and Motif on 1.5.0b15 ###@###.### 2003-8-21 ====================================================================== Name: adR10249 Date: 08/27/2003 ###@###.### 26-Aug-2003 This is not a bug. There is a thread race in MainThread (Test.java) and EventQueue. When we invoke setScrollPosition() we call the following code from ScrollPaneAdjustable.setTypedValue(): [..skip..] value = v; adjustmentListener.adjustmentValueChanged(event); [..skip..] And while adjustableEvent with value (45) isn't yet processed on EventQueue, next value (46) is already assigned to ScrollPane.value. Thus at that time when adjustableEvent (45) is processed by EventQueue Test.java checks for new value but value is equal to 45 because AdjustmentListener changed it. Here we have a bug in Test.java which was fixed in bug 4887824 Reg-test ScrollPositionTest.html has wrong tag ======================================================================
24-08-2004

PUBLIC COMMENTS The bug is no longer reproducible under JDK 1.1.8 under Solaris 2.6.
24-08-2004

SUGGESTED FIX we fixed this in jtg javasoft tree in delta: src/solaris/sun/awt_ScrollPane.c 1.16 by simply not adding XtCallback for XmNvalueChangedCallback This was causing recursive calls to setValue in the ScrollBarAdjustable when the value was repeatedly being set programaticly. andy.herrick@East 1998-03-05
05-03-1998