src/share/classes/javax/swing/JScrollPane.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 151  * Please see {@link java.beans.XMLEncoder}.
 152  *
 153  * @see JScrollBar
 154  * @see JViewport
 155  * @see ScrollPaneLayout
 156  * @see Scrollable
 157  * @see Component#getPreferredSize
 158  * @see #setViewportView
 159  * @see #setRowHeaderView
 160  * @see #setColumnHeaderView
 161  * @see #setCorner
 162  * @see #setViewportBorder
 163  *
 164  * @beaninfo
 165  *     attribute: isContainer true
 166  *     attribute: containerDelegate getViewport
 167  *   description: A specialized container that manages a viewport, optional scrollbars and headers
 168  *
 169  * @author Hans Muller
 170  */

 171 public class JScrollPane extends JComponent implements ScrollPaneConstants, Accessible
 172 {
 173     private Border viewportBorder;
 174 
 175     /**
 176      * @see #getUIClassID
 177      * @see #readObject
 178      */
 179     private static final String uiClassID = "ScrollPaneUI";
 180 
 181     /**
 182      * The display policy for the vertical scrollbar.
 183      * The default is
 184      * <code>ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED</code>.
 185      * @see #setVerticalScrollBarPolicy
 186      */
 187     protected int verticalScrollBarPolicy = VERTICAL_SCROLLBAR_AS_NEEDED;
 188 
 189 
 190     /**


 668      * that are instances
 669      * of this class.  <code>Scrollbar</code> overrides the
 670      * <code>getUnitIncrement</code> and <code>getBlockIncrement</code>
 671      * methods so that, if the viewport's view is a <code>Scrollable</code>,
 672      * the view is asked to compute these values. Unless
 673      * the unit/block increment have been explicitly set.
 674      * <p>
 675      * <strong>Warning:</strong>
 676      * Serialized objects of this class will not be compatible with
 677      * future Swing releases. The current serialization support is
 678      * appropriate for short term storage or RMI between applications running
 679      * the same version of Swing.  As of 1.4, support for long term storage
 680      * of all JavaBeans&trade;
 681      * has been added to the <code>java.beans</code> package.
 682      * Please see {@link java.beans.XMLEncoder}.
 683      *
 684      * @see Scrollable
 685      * @see JScrollPane#createVerticalScrollBar
 686      * @see JScrollPane#createHorizontalScrollBar
 687      */

 688     protected class ScrollBar extends JScrollBar implements UIResource
 689     {
 690         /**
 691          * Set to true when the unit increment has been explicitly set.
 692          * If this is false the viewport's view is obtained and if it
 693          * is an instance of <code>Scrollable</code> the unit increment
 694          * from it is used.
 695          */
 696         private boolean unitIncrementSet;
 697         /**
 698          * Set to true when the block increment has been explicitly set.
 699          * If this is false the viewport's view is obtained and if it
 700          * is an instance of <code>Scrollable</code> the block increment
 701          * from it is used.
 702          */
 703         private boolean blockIncrementSet;
 704 
 705         /**
 706          * Creates a scrollbar with the specified orientation.
 707          * The options are:


1424             accessibleContext = new AccessibleJScrollPane();
1425         }
1426         return accessibleContext;
1427     }
1428 
1429     /**
1430      * This class implements accessibility support for the
1431      * <code>JScrollPane</code> class.  It provides an implementation of the
1432      * Java Accessibility API appropriate to scroll pane user-interface
1433      * elements.
1434      * <p>
1435      * <strong>Warning:</strong>
1436      * Serialized objects of this class will not be compatible with
1437      * future Swing releases. The current serialization support is
1438      * appropriate for short term storage or RMI between applications running
1439      * the same version of Swing.  As of 1.4, support for long term storage
1440      * of all JavaBeans&trade;
1441      * has been added to the <code>java.beans</code> package.
1442      * Please see {@link java.beans.XMLEncoder}.
1443      */

1444     protected class AccessibleJScrollPane extends AccessibleJComponent
1445         implements ChangeListener, PropertyChangeListener {
1446 
1447         protected JViewport viewPort = null;
1448 
1449         /*
1450          * Resets the viewport ChangeListener and PropertyChangeListener
1451          */
1452         public void resetViewPort() {
1453             if (viewPort != null) {
1454                 viewPort.removeChangeListener(this);
1455                 viewPort.removePropertyChangeListener(this);
1456             }
1457             viewPort = JScrollPane.this.getViewport();
1458             if (viewPort != null) {
1459                 viewPort.addChangeListener(this);
1460                 viewPort.addPropertyChangeListener(this);
1461             }
1462         }
1463 


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 151  * Please see {@link java.beans.XMLEncoder}.
 152  *
 153  * @see JScrollBar
 154  * @see JViewport
 155  * @see ScrollPaneLayout
 156  * @see Scrollable
 157  * @see Component#getPreferredSize
 158  * @see #setViewportView
 159  * @see #setRowHeaderView
 160  * @see #setColumnHeaderView
 161  * @see #setCorner
 162  * @see #setViewportBorder
 163  *
 164  * @beaninfo
 165  *     attribute: isContainer true
 166  *     attribute: containerDelegate getViewport
 167  *   description: A specialized container that manages a viewport, optional scrollbars and headers
 168  *
 169  * @author Hans Muller
 170  */
 171 @SuppressWarnings("serial") // Same-version serialization only
 172 public class JScrollPane extends JComponent implements ScrollPaneConstants, Accessible
 173 {
 174     private Border viewportBorder;
 175 
 176     /**
 177      * @see #getUIClassID
 178      * @see #readObject
 179      */
 180     private static final String uiClassID = "ScrollPaneUI";
 181 
 182     /**
 183      * The display policy for the vertical scrollbar.
 184      * The default is
 185      * <code>ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED</code>.
 186      * @see #setVerticalScrollBarPolicy
 187      */
 188     protected int verticalScrollBarPolicy = VERTICAL_SCROLLBAR_AS_NEEDED;
 189 
 190 
 191     /**


 669      * that are instances
 670      * of this class.  <code>Scrollbar</code> overrides the
 671      * <code>getUnitIncrement</code> and <code>getBlockIncrement</code>
 672      * methods so that, if the viewport's view is a <code>Scrollable</code>,
 673      * the view is asked to compute these values. Unless
 674      * the unit/block increment have been explicitly set.
 675      * <p>
 676      * <strong>Warning:</strong>
 677      * Serialized objects of this class will not be compatible with
 678      * future Swing releases. The current serialization support is
 679      * appropriate for short term storage or RMI between applications running
 680      * the same version of Swing.  As of 1.4, support for long term storage
 681      * of all JavaBeans&trade;
 682      * has been added to the <code>java.beans</code> package.
 683      * Please see {@link java.beans.XMLEncoder}.
 684      *
 685      * @see Scrollable
 686      * @see JScrollPane#createVerticalScrollBar
 687      * @see JScrollPane#createHorizontalScrollBar
 688      */
 689     @SuppressWarnings("serial") // Same-version serialization only
 690     protected class ScrollBar extends JScrollBar implements UIResource
 691     {
 692         /**
 693          * Set to true when the unit increment has been explicitly set.
 694          * If this is false the viewport's view is obtained and if it
 695          * is an instance of <code>Scrollable</code> the unit increment
 696          * from it is used.
 697          */
 698         private boolean unitIncrementSet;
 699         /**
 700          * Set to true when the block increment has been explicitly set.
 701          * If this is false the viewport's view is obtained and if it
 702          * is an instance of <code>Scrollable</code> the block increment
 703          * from it is used.
 704          */
 705         private boolean blockIncrementSet;
 706 
 707         /**
 708          * Creates a scrollbar with the specified orientation.
 709          * The options are:


1426             accessibleContext = new AccessibleJScrollPane();
1427         }
1428         return accessibleContext;
1429     }
1430 
1431     /**
1432      * This class implements accessibility support for the
1433      * <code>JScrollPane</code> class.  It provides an implementation of the
1434      * Java Accessibility API appropriate to scroll pane user-interface
1435      * elements.
1436      * <p>
1437      * <strong>Warning:</strong>
1438      * Serialized objects of this class will not be compatible with
1439      * future Swing releases. The current serialization support is
1440      * appropriate for short term storage or RMI between applications running
1441      * the same version of Swing.  As of 1.4, support for long term storage
1442      * of all JavaBeans&trade;
1443      * has been added to the <code>java.beans</code> package.
1444      * Please see {@link java.beans.XMLEncoder}.
1445      */
1446     @SuppressWarnings("serial") // Same-version serialization only
1447     protected class AccessibleJScrollPane extends AccessibleJComponent
1448         implements ChangeListener, PropertyChangeListener {
1449 
1450         protected JViewport viewPort = null;
1451 
1452         /*
1453          * Resets the viewport ChangeListener and PropertyChangeListener
1454          */
1455         public void resetViewPort() {
1456             if (viewPort != null) {
1457                 viewPort.removeChangeListener(this);
1458                 viewPort.removePropertyChangeListener(this);
1459             }
1460             viewPort = JScrollPane.this.getViewport();
1461             if (viewPort != null) {
1462                 viewPort.addChangeListener(this);
1463                 viewPort.addPropertyChangeListener(this);
1464             }
1465         }
1466