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

java.awt.ScrollPane#setScrollPosition() Problem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.1.7
    • client-libs
    • x86
    • windows_nt



      Name: dbT83986 Date: 03/21/99


      After call java.awt.ScrollPane#setScrollPosition(),
      a component in ScrollPane slieded 2dots a moment.
      So component image flickers.
      But when Scrollbar's Thumb pressed, did'n this problem.

      1)Execute following Souce(ScrollPaneTest.java).
      2)Press DownKey or UpKey.
      3)ScrollPaneTest$ChildPane will be off to the right side
        about 2 dots.

      This Problem happen JDK1.1.7 or later(JDK1.2);
      Before JDK1.1.6 not happened.

      Thank you.

      =================ScrollPaneTest.java=========================
      import java.awt.*;
      import java.awt.event.*;

      public class ScrollPaneTest extends ScrollPane {
          public static void main(String[] args) {
              Frame f = new Frame("ScrollPaneTest");
              ScrollPane sp = new ScrollPaneTest(300, 300);
              f.add(sp);
              f.setSize(100, 100);
              f.show();
              sp.requestFocus();
          }

          public ScrollPaneTest(int w, int h) {
              super(ScrollPane.SCROLLBARS_AS_NEEDED);
              Component c = new ChildPane(w, h);
              addImpl(c, null, 0);
          }

          class ChildPane extends Component implements KeyListener, FocusListener {
              int Margin = 10;
              public ChildPane(int w, int h) {
                  setSize(w, h);
                  addKeyListener(this);
                  ScrollPaneTest.this.addFocusListener(this);
              }

              public Dimension getPreferredSize() {
                  return(getSize());
              }

              public void paint(Graphics g) {
                  Rectangle rect = g.getClipBounds();
                  g.setColor(Color.black);
                  for(int x = Margin; x < rect.x + rect.width; x += Margin)
                      g.drawLine(x, rect.y, x, rect.y + rect.height);
              }

              public void keyPressed(KeyEvent e) {
                  int Key = e.getKeyCode();
                  if(Key == KeyEvent.VK_UP) {
                      Point pos = getScrollPosition();
                      setScrollPosition(pos.x, pos.y - 5);
                  }
                  else if(Key == KeyEvent.VK_DOWN) {
                      Point pos = getScrollPosition();
                      setScrollPosition(pos.x, pos.y + 5);
                  }
              }

              public void keyTyped(KeyEvent e) { }

              public void keyReleased(KeyEvent e) { }

              public void focusGained(FocusEvent e) {
                  requestFocus();
              }

              public void focusLost(FocusEvent e) { }
              }
          }

      =================ScrollPaneTest.java=========================
      (Review ID: 55685)
      ======================================================================

            xdengsunw Xianfa Deng (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: