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

JViewport.scrollRectToVisible allows scrolling beyond bounds of component

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.0
    • 1.2.0, 1.2.2, 1.2.2_05a
    • client-libs
    • beta
    • generic, x86, sparc
    • generic, solaris_2.6, windows_nt

      Bring up the following test, click on the scroll button and then click it again. Notice that you see row 98 and 99 twice. JViewport.scrollRectToVisible, if passed a bounds greater than the viewport views bounds, scrolls the viewport view such that the viewport does not completely contain the view. scrollRectToVisible should now allow this to happen.
      import javax.swing.*;
      import javax.swing.table.*;
      import java.awt.*;
      import java.awt.event.*;

      public class ScrollRectToVisibleTest {
          public static void main(String[] args) {
      JFrame frame = new JFrame("test");
      final JTable table = new JTable(new TestModel());
      JButton scrollButton = new JButton("Scroll");

      scrollButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
      Rectangle bounds = table.getBounds();
      bounds.y = bounds.height + table.getRowHeight();
      bounds.height = table.getRowHeight();
      System.out.println("scrolling: " + bounds);
      table.scrollRectToVisible(bounds);
      System.out.println("bounds: " + table.getVisibleRect());
      }
      });
      frame.getContentPane().add(new JScrollPane(table),
      BorderLayout.CENTER);
      frame.getContentPane().add(scrollButton, BorderLayout.SOUTH);
      frame.pack();
      frame.show();
          }


          static class TestModel extends AbstractTableModel {
      public String getColumnName(int column) {
      return Integer.toString(column);
      }
              
      public int getRowCount() {
      return 100;
      }

      public int getColumnCount() {
      return 5;
      }

      public Object getValueAt(int row, int col) {
      return row + " x " + col;
      }

      public boolean isCellEditable(int row, int column) { return false; }

      public void setValueAt(Object value, int row, int col) {
      }
          }

      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: