JDK-4681561 : Adjustable.setValue() does not set value
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2002-05-08
  • Updated: 2002-05-09
  • Resolved: 2002-05-09
Related Reports
Relates :  
Description

Name: atR10191			Date: 05/08/2002


specification for method
 public void setValue(int v)
of interface Adjustable states:

"Sets the current value of the adjustable object. This value must be within the
 range defined by the minimum and maximum values for this object."

The example below shows that in fact the method does not set the
current value.
Adjustable is obtained by mean of ScrollPane.getVAdjustable() call.
============ Test129.java ==============================================
import java.awt.*;
import java.awt.event.*;

public class Test129 {
    public static void main(String argv[]) {
        Test129 test = new Test129();
        test.testRun();
    }

    public void testRun() {
        Frame frm = new Frame();
        frm.setSize(100,100);

        ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
        frm.add(sp);
        sp.add(new Button("ppp"));
    
        MyComponentAdapter listener = new MyComponentAdapter();
        frm.addComponentListener(listener);    
 
        synchronized (listener) {
            frm.setVisible(true);
            // here we are waiting for components to be drawn
            // (else minimum and maximum can be 0)
            try {  
                listener.wait();
            } catch (InterruptedException e) {
            }
        }

        Adjustable adjustable = sp.getVAdjustable();

        int minimum = adjustable.getMinimum();
        int maximum = adjustable.getMaximum();        
        int newValue = Math.min(minimum + 1, maximum);

        adjustable.setValue(newValue);

        if (adjustable.getValue() != newValue) {
            System.out.println(" failed");
            System.out.println("was set: " + newValue);
            System.out.println("adjustable.getValue(): " + 
                                adjustable.getValue());
            System.out.println("minimum: " + minimum);
            System.out.println("maximum: " + maximum);
            System.exit(1);
        }
        System.out.println("OKAY");
        System.exit(0);
    }
}

class MyComponentAdapter extends ComponentAdapter {
    synchronized public void componentShown(ComponentEvent e) {
        notify();
    }
}
======== end of Test129.java ==========================================
======== output ========
 failed
was set: 1
adjustable.getValue(): 0
minimum: 0
maximum: 60
======== end of output ========
======================================================================

Comments
EVALUATION Should fix in mantis (JCK). ###@###.### 2002-05-08 This is a problem with the test case which was probably made due to incomplete docs for Adjustable.setValue(). Scrollbar, which implements Adjustable, is more specific about what values are legal: "Sets the value of this scroll bar to the specified value. If the value supplied is less than the current minimum or greater than the current maximum - visibleAmount, then one of those values is substituted, as appropriate." In the test case, the Adjustable's values are: minimum: 0 maximum: 45 visible: 45 Going by the Scrollbar docs, the only legal value is 0. This is why calling setValue(1) doesn't work. The easiest way to fix this is probably to add a larger Component to the ScrollPane. I used a 300x300 Canvas. I will file a doc bug to have the docs better specified. ###@###.### 2002-05-09 New doc bug is 4682598. ###@###.### 2002-05-09
09-05-2002