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

fp.bugs 2194 Win32: Scrollbar should move the canvas as the scrollbar moves

XMLWordPrintable

    • 1.1
    • x86
    • windows_nt
    • Not verified

      julie melbin <###@###.###>

      Win32 only: As you move the scrollbar, the associated canvas should move with it. It should
      not wait until you release the scrollbar

      Steps to reproduce
      Compile the included code
      Run the included code
      Use the mouse to move either the horizontal or vertical scrollbar thumb (elevator) boxes
      // note: the canvas does not move with the scrollbar until you release the mouse

      /*
       * %W% %G% %U% Arthur van Hoff
       *
       * Modified: Vijay Srinivasan
       * Date: 11/06/95
       * Comment: app to applet conversion.
       *
       * Modified: Kevin A. Smith
       * Date: 11/10/95
       * Comment: Added BorderLayout manager to Applet
       * Changed Frame to AppFrame
       *
       */
       
      import java.awt.*;
      import java.applet.*;

      class ScrollablePaintCanvas extends Canvas {
          int tx = 20;
          int ty = 100;
          static final int SIZE = 500;

          public void paint(Graphics g)
          {
             g.translate(-tx, -ty);

             for (int i = 0 ; i < 200 ; i += 20) {
                g.drawOval(i, i, SIZE - 2*i, SIZE - 2*i);
             }
             g.setColor(Color.yellow);
             g.drawLine(0, SIZE/2, SIZE, SIZE/2);
             g.drawLine(SIZE/2, 0, SIZE/2, SIZE);

             g.setColor(Color.red);
             g.fillOval(SIZE/2 - 20, SIZE/2 - 20, 40, 40);
          }
      }

      /**
       * A test of a Container with BorderLayout.
       */
      public class ScrollbarTest extends Applet
      {
          Scrollbar vert;
          Scrollbar horz;
          ScrollablePaintCanvas cv;

          public void init()
          {
             // Added layout manager
             setLayout( new BorderLayout() );
          
             add("Center", cv = new ScrollablePaintCanvas());
             add("East", vert = new Scrollbar(Scrollbar.VERTICAL,
                                              cv.ty,
                                              100,
                                              0,
                                              ScrollablePaintCanvas.SIZE) );
              add("South", horz = new Scrollbar(Scrollbar.HORIZONTAL,
                                                cv.tx,
                                                100,
                                                0,
                                                ScrollablePaintCanvas.SIZE) );
             reshape(100, 200, 300, 250);
          }

          public boolean handleEvent(Event evt)
          {
             if (evt.target == vert) {
                cv.ty = ((Integer)evt.arg).intValue();
                cv.repaint();
                return true;
             }

             if (evt.target == horz) {
                cv.tx = ((Integer)evt.arg).intValue();
                cv.repaint();
                return true;
             }
             return super.handleEvent(evt);

          }

          public static void main(String args[])
          {
             Frame f = new AppFrame("ScrollbarTest");
             ScrollbarTest scrollbartest = new ScrollbarTest();

             scrollbartest.init();
             scrollbartest.start();

             f.resize(200, 200);
             f.add("Center", scrollbartest);
             f.show();
          }
      }

      /* Generic Application Frame
       * @(#)AppFrame.java 1.2 08 Nov 1995 10:00:20
       * @author Kevin A. Smith
       */

      import java.awt.Frame;
      import java.awt.Event;

      // Application Frame window
      class AppFrame extends Frame
      {
          // constructor needed to pass window title to class Frame
          public AppFrame(String name)
          {
             // call java.awt.Frame(String) constructor
             super(name);
          }

          // needed to allow window close
          public boolean handleEvent(Event e)
          {
             // Window Destroy event
             if (e.id == Event.WINDOW_DESTROY)
             {
                // exit the program
                System.exit(0);
                return true;
             }
             
             // it's good form to let the super class look at any
             // unhandled events
             return super.handleEvent(e);

          } // end handleEvent()
      }

            tballsunw Tom Ball (Inactive)
            kasmithsunw Kevin Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: