src/java.desktop/share/classes/java/awt/ScrollPane.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 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
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.awt.peer.LightweightPeer;
  28 import java.awt.peer.ScrollPanePeer;
  29 import java.awt.event.*;
  30 import javax.accessibility.*;
  31 import sun.awt.ScrollPaneWheelScroller;
  32 import sun.awt.SunToolkit;
  33 
  34 import java.beans.ConstructorProperties;
  35 import java.beans.Transient;
  36 import java.io.ObjectInputStream;
  37 import java.io.ObjectOutputStream;
  38 import java.io.IOException;
  39 
  40 /**
  41  * A container class which implements automatic horizontal and/or
  42  * vertical scrolling for a single child component.  The display
  43  * policy for the scrollbars can be set to:
  44  * <OL>
  45  * <LI>as needed: scrollbars created and shown only when needed by scrollpane
  46  * <LI>always: scrollbars created and always shown by the scrollpane
  47  * <LI>never: scrollbars never created or shown by the scrollpane


 545      * Creates the scroll pane's peer.
 546      */
 547     public void addNotify() {
 548         synchronized (getTreeLock()) {
 549 
 550             int vAdjustableValue = 0;
 551             int hAdjustableValue = 0;
 552 
 553             // Bug 4124460. Save the current adjustable values,
 554             // so they can be restored after addnotify. Set the
 555             // adjustables to 0, to prevent crashes for possible
 556             // negative values.
 557             if (getComponentCount() > 0) {
 558                 vAdjustableValue = vAdjustable.getValue();
 559                 hAdjustableValue = hAdjustable.getValue();
 560                 vAdjustable.setValue(0);
 561                 hAdjustable.setValue(0);
 562             }
 563 
 564             if (peer == null)
 565                 peer = getToolkit().createScrollPane(this);
 566             super.addNotify();
 567 
 568             // Bug 4124460. Restore the adjustable values.
 569             if (getComponentCount() > 0) {
 570                 vAdjustable.setValue(vAdjustableValue);
 571                 hAdjustable.setValue(hAdjustableValue);
 572             }
 573         }
 574     }
 575 
 576     /**
 577      * Returns a string representing the state of this
 578      * <code>ScrollPane</code>. This
 579      * method is intended to be used only for debugging purposes, and the
 580      * content and format of the returned string may vary between
 581      * implementations. The returned string may be empty but may not be
 582      * <code>null</code>.
 583      *
 584      * @return the parameter string of this scroll pane
 585      */


   1 /*
   2  * Copyright (c) 1996, 2015, 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
  23  * questions.
  24  */
  25 package java.awt;
  26 

  27 import java.awt.peer.ScrollPanePeer;
  28 import java.awt.event.*;
  29 import javax.accessibility.*;
  30 import sun.awt.ScrollPaneWheelScroller;
  31 import sun.awt.SunToolkit;
  32 
  33 import java.beans.ConstructorProperties;
  34 import java.beans.Transient;
  35 import java.io.ObjectInputStream;
  36 import java.io.ObjectOutputStream;
  37 import java.io.IOException;
  38 
  39 /**
  40  * A container class which implements automatic horizontal and/or
  41  * vertical scrolling for a single child component.  The display
  42  * policy for the scrollbars can be set to:
  43  * <OL>
  44  * <LI>as needed: scrollbars created and shown only when needed by scrollpane
  45  * <LI>always: scrollbars created and always shown by the scrollpane
  46  * <LI>never: scrollbars never created or shown by the scrollpane


 544      * Creates the scroll pane's peer.
 545      */
 546     public void addNotify() {
 547         synchronized (getTreeLock()) {
 548 
 549             int vAdjustableValue = 0;
 550             int hAdjustableValue = 0;
 551 
 552             // Bug 4124460. Save the current adjustable values,
 553             // so they can be restored after addnotify. Set the
 554             // adjustables to 0, to prevent crashes for possible
 555             // negative values.
 556             if (getComponentCount() > 0) {
 557                 vAdjustableValue = vAdjustable.getValue();
 558                 hAdjustableValue = hAdjustable.getValue();
 559                 vAdjustable.setValue(0);
 560                 hAdjustable.setValue(0);
 561             }
 562 
 563             if (peer == null)
 564                 peer = getComponentFactory().createScrollPane(this);
 565             super.addNotify();
 566 
 567             // Bug 4124460. Restore the adjustable values.
 568             if (getComponentCount() > 0) {
 569                 vAdjustable.setValue(vAdjustableValue);
 570                 hAdjustable.setValue(hAdjustableValue);
 571             }
 572         }
 573     }
 574 
 575     /**
 576      * Returns a string representing the state of this
 577      * <code>ScrollPane</code>. This
 578      * method is intended to be used only for debugging purposes, and the
 579      * content and format of the returned string may vary between
 580      * implementations. The returned string may be empty but may not be
 581      * <code>null</code>.
 582      *
 583      * @return the parameter string of this scroll pane
 584      */