在本例中,scrollRectToVisible个函数起什么作用?javadoc里这么说得:scrollRectToVisible
public void scrollRectToVisible(Rectangle aRect)Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as JViewport, override this method and perform the scrolling. Parameters:
aRect - the visible Rectangle
See Also:
JViewport
--------------------------------------------------------------------------------------按javadoc里说明的,Rectangle(150,150,300,300)构造函数的四个参数分别为:
public Rectangle(int x,
                 int y,
                 int width,
                 int height)那按本例:坐标为150.150  宽高为300,是不是滚动条(矩形)为300的正方形?实际运行时不是这样的。/*
 * TestJScrollPane.java
 *
 * Created on July 30, 2002, 11:35 AM
 */package ch16;import java.awt.*;
import javax.swing.*;
import java.awt.event.*;/**
 *
 * @author  Stephen Potts
 * @version
 */
public class TestJScrollPane extends JFrame
{
   JScrollPane sp;
   JTextField tf1;
   JTextField tf2;
   JTextField tf3;
   JTextField tf4;
   JTextField tf5;
   JTextField tf6;
   JTextField tf7;
   JTextField tf8;
   
   /** Creates new TestJScrollPane */
   public TestJScrollPane()
   {
      //create eight text fields
      tf1 = new JTextField("Text Field Number 1 ");
      tf2 = new JTextField("Text Field Number 2 ");
      tf3 = new JTextField("Text Field Number 3 ");
      tf4 = new JTextField("Text Field Number 4 ");
      tf5 = new JTextField("Text Field Number 5 ");
      tf6 = new JTextField("Text Field Number 6 ");
      tf7 = new JTextField("Text Field Number 7 ");
      tf8 = new JTextField("Text Field Number 8 ");
      
      //add the panel
      JPanel p1 = new JPanel();
      p1.add(tf1);
      p1.add(tf2);
      p1.add(tf3);
      p1.add(tf4);
      p1.add(tf5);
      p1.add(tf6);
      p1.add(tf7);
      p1.add(tf8);      //create the scroll pane
      sp = new JScrollPane(p1);
      sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);      getContentPane().add(sp);
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setTitle("Using a JScrollPane");
      setBounds( 100, 100, 300, 300);
      setVisible(true);
      sp.scrollRectToVisible(new Rectangle(150,150,300,300));
   }
   
   public static void main(String[] args)
   {
      TestJScrollPane tsp = new TestJScrollPane();
   }
   
}