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

scrollbar in JScrollPane will not allowing scrolling to bottom of view.

XMLWordPrintable

    • 1.1.5
    • sparc
    • solaris_2.5.1
    • Not verified

      If you have a relatively large view contained in the scrollpane (say height of 16000) clicking and dragging on the vertical scrollbar will not allow dragging to bottom of the document (you can drag almost to the bottom and then you have to use the down arrow to get to the true bottom).

      Here is some code to reproduce it:
      import com.sun.java.swing.JComponent;
      import com.sun.java.swing.JFrame;
      import com.sun.java.swing.JScrollBar;
      import com.sun.java.swing.JScrollPane;
      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import java.awt.Rectangle;

      /**
       * This example shows a bug in JScrollPane. The following example will
       * bring up a window with a JScrollPane. The JScrollPane displays a bunch
       * of rows, going from 0 to 999. If you grab the scrollbar and drag as
       * far down as possible only row 998 will be visible. Clicking on the
       * down arrow will scroll down 999. Once this is visible if you again click
       * on the vertical scrollbar it'll jump back to 998:(
       * This behavior gets worse the bigger the view in the viewport gets and
       * smaller the scrollpane gets.
       */
      public class ScrollBug
      {
        public static void main(String[] args) {
          JFrame frame = new JFrame("Scroll Bug");
          JScrollPane scrollPane = new JScrollPane();

          scrollPane.setViewportView(new JComponent() {
            public Dimension getPreferredSize() {
      return new Dimension(300, 16000);
            }
            public void paint(Graphics g) {
      Rectangle clipRect = g.getClipBounds();
      int beginRow = clipRect.y / 16;
      int endRow = (clipRect.y + clipRect.height) / 16;

      g.setColor(Color.red);
      for(int counter = beginRow; counter <= endRow; counter++) {
      g.drawRect(10, counter * 16, 200, 16);
      g.drawString(Integer.toString(counter), 10, (counter + 1) * 16);
      }
            }
          });

          frame.setLayout(new BorderLayout());
          frame.add(scrollPane);
          frame.pack();
          frame.setBounds(100, 100, 400, 400);
          frame.show();
        }
      }

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: