Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4680670

Adjustable.setValue() does not notify AdjustmentListener

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.1, 1.3.0, 1.4.0
    • client-libs
    • None
    • generic, sparc
    • generic, solaris_7



      Name: atR10191 Date: 05/07/2002


      specifications for method
       public void addAdjustmentListener(AdjustmentListener l)
      of interface Adjustable states:

      "Add a listener to recieve adjustment events when the value of the adjustable
       object changes"

      The example below shows that call of setValue() does not cause
      listener to be notified.
      Adjustable is obtained by mean of ScrollPane.getVAdjustable() call.
      Test example hangs.
      ============ Test127.java ==============================================
      import java.awt.*;
      import java.awt.event.*;

      public class Test127 {
          public static void main(String argv[]) {
              Test127 test = new Test127();
              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);

              if (adjustable.getValue() != newValue) {
                  MyAdjustmentListener al = new MyAdjustmentListener();
                  adjustable.addAdjustmentListener(al);
                  adjustable.setValue(newValue);

                  synchronized (al) {
                      try {
                          while(!al.changed) {
                              al.wait();
                          }
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                          System.out.println(" interrupted");
                          System.exit(1);
                      }
                  }
              }
              System.out.println("OKAY");
              System.exit(0);
          }
      }

      class MyAdjustmentListener implements AdjustmentListener {
          boolean changed = false;

          synchronized public void adjustmentValueChanged(AdjustmentEvent e){
              changed = true;
              notify();
          }
      }

      class MyComponentAdapter extends ComponentAdapter {
          synchronized public void componentShown(ComponentEvent e) {
              notify();
          }
      }
      ======== end of Test127.java ==========================================
      there is no output
      ==================================================
      ======================================================================

            bchristi Brent Christian
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: