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 ========
======================================================================