src/share/classes/java/awt/Scrollbar.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


 144  * <code>Event.SCROLL_LINE_UP</code>
 145  * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> replaces
 146  * <code>Event.SCROLL_LINE_DOWN</code>
 147  * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> replaces
 148  * <code>Event.SCROLL_PAGE_UP</code>
 149  * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> replaces
 150  * <code>Event.SCROLL_PAGE_DOWN</code>
 151  * </ul>
 152  * <p>
 153  * <b>Note</b>: We recommend using a <code>Scrollbar</code>
 154  * for value selection only.  If you want to implement
 155  * a scrollable component inside a container, we recommend you use
 156  * a {@link ScrollPane ScrollPane}. If you use a
 157  * <code>Scrollbar</code> for this purpose, you are likely to
 158  * encounter issues with painting, key handling, sizing and
 159  * positioning.
 160  *
 161  * @author      Sami Shaio
 162  * @see         java.awt.event.AdjustmentEvent
 163  * @see         java.awt.event.AdjustmentListener
 164  * @since       JDK1.0
 165  */
 166 public class Scrollbar extends Component implements Adjustable, Accessible {
 167 
 168     /**
 169      * A constant that indicates a horizontal scroll bar.
 170      */
 171     public static final int     HORIZONTAL = 0;
 172 
 173     /**
 174      * A constant that indicates a vertical scroll bar.
 175      */
 176     public static final int     VERTICAL   = 1;
 177 
 178     /**
 179      * The value of the <code>Scrollbar</code>.
 180      * This property must be greater than or equal to <code>minimum</code>
 181      * and less than or equal to
 182      * <code>maximum - visibleAmount</code>
 183      *
 184      * @serial


 443      *
 444      * @return    the orientation of this scroll bar, either
 445      *               <code>Scrollbar.HORIZONTAL</code> or
 446      *               <code>Scrollbar.VERTICAL</code>
 447      * @see       java.awt.Scrollbar#setOrientation
 448      */
 449     public int getOrientation() {
 450         return orientation;
 451     }
 452 
 453     /**
 454      * Sets the orientation for this scroll bar.
 455      *
 456      * @param orientation  the orientation of this scroll bar, either
 457      *               <code>Scrollbar.HORIZONTAL</code> or
 458      *               <code>Scrollbar.VERTICAL</code>
 459      * @see       java.awt.Scrollbar#getOrientation
 460      * @exception   IllegalArgumentException  if the value supplied
 461      *                   for <code>orientation</code> is not a
 462      *                   legal value
 463      * @since     JDK1.1
 464      */
 465     public void setOrientation(int orientation) {
 466         synchronized (getTreeLock()) {
 467             if (orientation == this.orientation) {
 468                 return;
 469             }
 470             switch (orientation) {
 471                 case HORIZONTAL:
 472                 case VERTICAL:
 473                     this.orientation = orientation;
 474                     break;
 475                 default:
 476                     throw new IllegalArgumentException("illegal scrollbar orientation");
 477             }
 478             /* Create a new peer with the specified orientation. */
 479             if (peer != null) {
 480                 removeNotify();
 481                 addNotify();
 482                 invalidate();
 483             }


 549      * <p>
 550      * When <code>setMinimum</code> is called, the minimum value
 551      * is changed, and other values (including the maximum, the
 552      * visible amount, and the current scroll bar value)
 553      * are changed to be consistent with the new minimum.
 554      * <p>
 555      * Normally, a program should change a scroll bar's minimum
 556      * value only by calling <code>setValues</code>.
 557      * The <code>setValues</code> method simultaneously
 558      * and synchronously sets the minimum, maximum, visible amount,
 559      * and value properties of a scroll bar, so that they are
 560      * mutually consistent.
 561      * <p>
 562      * Note that setting the minimum value to <code>Integer.MAX_VALUE</code>
 563      * will result in the new minimum value being set to
 564      * <code>Integer.MAX_VALUE - 1</code>.
 565      *
 566      * @param       newMinimum   the new minimum value for this scroll bar
 567      * @see         java.awt.Scrollbar#setValues
 568      * @see         java.awt.Scrollbar#setMaximum
 569      * @since       JDK1.1
 570      */
 571     public void setMinimum(int newMinimum) {
 572         // No checks are necessary in this method since minimum is
 573         // the first variable checked in the setValues function.
 574 
 575         // Use setValues so that a consistent policy relating
 576         // minimum, maximum, visible amount, and value is enforced.
 577         setValues(value, visibleAmount, newMinimum, maximum);
 578     }
 579 
 580     /**
 581      * Gets the maximum value of this scroll bar.
 582      *
 583      * @return      the maximum value of this scroll bar
 584      * @see         java.awt.Scrollbar#getValue
 585      * @see         java.awt.Scrollbar#getMinimum
 586      */
 587     public int getMaximum() {
 588         return maximum;
 589     }


 594      * When <code>setMaximum</code> is called, the maximum value
 595      * is changed, and other values (including the minimum, the
 596      * visible amount, and the current scroll bar value)
 597      * are changed to be consistent with the new maximum.
 598      * <p>
 599      * Normally, a program should change a scroll bar's maximum
 600      * value only by calling <code>setValues</code>.
 601      * The <code>setValues</code> method simultaneously
 602      * and synchronously sets the minimum, maximum, visible amount,
 603      * and value properties of a scroll bar, so that they are
 604      * mutually consistent.
 605      * <p>
 606      * Note that setting the maximum value to <code>Integer.MIN_VALUE</code>
 607      * will result in the new maximum value being set to
 608      * <code>Integer.MIN_VALUE + 1</code>.
 609      *
 610      * @param       newMaximum   the new maximum value
 611      *                     for this scroll bar
 612      * @see         java.awt.Scrollbar#setValues
 613      * @see         java.awt.Scrollbar#setMinimum
 614      * @since       JDK1.1
 615      */
 616     public void setMaximum(int newMaximum) {
 617         // minimum is checked first in setValues, so we need to
 618         // enforce minimum and maximum checks here.
 619         if (newMaximum == Integer.MIN_VALUE) {
 620             newMaximum = Integer.MIN_VALUE + 1;
 621         }
 622 
 623         if (minimum >= newMaximum) {
 624             minimum = newMaximum - 1;
 625         }
 626 
 627         // Use setValues so that a consistent policy relating
 628         // minimum, maximum, visible amount, and value is enforced.
 629         setValues(value, visibleAmount, minimum, newMaximum);
 630     }
 631 
 632     /**
 633      * Gets the visible amount of this scroll bar.
 634      * <p>
 635      * When a scroll bar is used to select a range of values,
 636      * the visible amount is used to represent the range of values
 637      * that are currently visible.  The size of the scroll bar's
 638      * bubble (also called a thumb or scroll box), usually gives a
 639      * visual representation of the relationship of the visible
 640      * amount to the range of the scroll bar.
 641      * Note that depending on platform, the value of the visible amount property
 642      * may not be visually indicated by the size of the bubble.
 643      * <p>
 644      * The scroll bar's bubble may not be displayed when it is not
 645      * moveable (e.g. when it takes up the entire length of the
 646      * scroll bar's track, or when the scroll bar is disabled).
 647      * Whether the bubble is displayed or not will not affect
 648      * the value returned by <code>getVisibleAmount</code>.
 649      *
 650      * @return      the visible amount of this scroll bar
 651      * @see         java.awt.Scrollbar#setVisibleAmount
 652      * @since       JDK1.1
 653      */
 654     public int getVisibleAmount() {
 655         return getVisible();
 656     }
 657 
 658     /**
 659      * @deprecated As of JDK version 1.1,
 660      * replaced by <code>getVisibleAmount()</code>.
 661      */
 662     @Deprecated
 663     public int getVisible() {
 664         return visibleAmount;
 665     }
 666 
 667     /**
 668      * Sets the visible amount of this scroll bar.
 669      * <p>
 670      * When a scroll bar is used to select a range of values,
 671      * the visible amount is used to represent the range of values
 672      * that are currently visible.  The size of the scroll bar's


 680      * moveable (e.g. when it takes up the entire length of the
 681      * scroll bar's track, or when the scroll bar is disabled).
 682      * Whether the bubble is displayed or not will not affect
 683      * the value returned by <code>getVisibleAmount</code>.
 684      * <p>
 685      * If the visible amount supplied is less than <code>one</code>
 686      * or greater than the current <code>maximum - minimum</code>,
 687      * then either <code>one</code> or <code>maximum - minimum</code>
 688      * is substituted, as appropriate.
 689      * <p>
 690      * Normally, a program should change a scroll bar's
 691      * value only by calling <code>setValues</code>.
 692      * The <code>setValues</code> method simultaneously
 693      * and synchronously sets the minimum, maximum, visible amount,
 694      * and value properties of a scroll bar, so that they are
 695      * mutually consistent.
 696      *
 697      * @param       newAmount the new visible amount
 698      * @see         java.awt.Scrollbar#getVisibleAmount
 699      * @see         java.awt.Scrollbar#setValues
 700      * @since       JDK1.1
 701      */
 702     public void setVisibleAmount(int newAmount) {
 703         // Use setValues so that a consistent policy relating
 704         // minimum, maximum, visible amount, and value is enforced.
 705         setValues(value, newAmount, minimum, maximum);
 706     }
 707 
 708     /**
 709      * Sets the unit increment for this scroll bar.
 710      * <p>
 711      * The unit increment is the value that is added or subtracted
 712      * when the user activates the unit increment area of the
 713      * scroll bar, generally through a mouse or keyboard gesture
 714      * that the scroll bar receives as an adjustment event.
 715      * The unit increment must be greater than zero.
 716      * Attepts to set the unit increment to a value lower than 1
 717      * will result in a value of 1 being set.
 718      * <p>
 719      * In some operating systems, this property
 720      * can be ignored by the underlying controls.
 721      *
 722      * @param        v  the amount by which to increment or decrement
 723      *                         the scroll bar's value
 724      * @see          java.awt.Scrollbar#getUnitIncrement
 725      * @since        JDK1.1
 726      */
 727     public void setUnitIncrement(int v) {
 728         setLineIncrement(v);
 729     }
 730 
 731     /**
 732      * @deprecated As of JDK version 1.1,
 733      * replaced by <code>setUnitIncrement(int)</code>.
 734      */
 735     @Deprecated
 736     public synchronized void setLineIncrement(int v) {
 737         int tmp = (v < 1) ? 1 : v;
 738 
 739         if (lineIncrement == tmp) {
 740             return;
 741         }
 742         lineIncrement = tmp;
 743 
 744         ScrollbarPeer peer = (ScrollbarPeer)this.peer;
 745         if (peer != null) {
 746             peer.setLineIncrement(lineIncrement);
 747         }
 748     }
 749 
 750     /**
 751      * Gets the unit increment for this scrollbar.
 752      * <p>
 753      * The unit increment is the value that is added or subtracted
 754      * when the user activates the unit increment area of the
 755      * scroll bar, generally through a mouse or keyboard gesture
 756      * that the scroll bar receives as an adjustment event.
 757      * The unit increment must be greater than zero.
 758      * <p>
 759      * In some operating systems, this property
 760      * can be ignored by the underlying controls.
 761      *
 762      * @return      the unit increment of this scroll bar
 763      * @see         java.awt.Scrollbar#setUnitIncrement
 764      * @since       JDK1.1
 765      */
 766     public int getUnitIncrement() {
 767         return getLineIncrement();
 768     }
 769 
 770     /**
 771      * @deprecated As of JDK version 1.1,
 772      * replaced by <code>getUnitIncrement()</code>.
 773      */
 774     @Deprecated
 775     public int getLineIncrement() {
 776         return lineIncrement;
 777     }
 778 
 779     /**
 780      * Sets the block increment for this scroll bar.
 781      * <p>
 782      * The block increment is the value that is added or subtracted
 783      * when the user activates the block increment area of the
 784      * scroll bar, generally through a mouse or keyboard gesture
 785      * that the scroll bar receives as an adjustment event.
 786      * The block increment must be greater than zero.
 787      * Attepts to set the block increment to a value lower than 1
 788      * will result in a value of 1 being set.
 789      *
 790      * @param        v  the amount by which to increment or decrement
 791      *                         the scroll bar's value
 792      * @see          java.awt.Scrollbar#getBlockIncrement
 793      * @since        JDK1.1
 794      */
 795     public void setBlockIncrement(int v) {
 796         setPageIncrement(v);
 797     }
 798 
 799     /**
 800      * @deprecated As of JDK version 1.1,
 801      * replaced by <code>setBlockIncrement()</code>.
 802      */
 803     @Deprecated
 804     public synchronized void setPageIncrement(int v) {
 805         int tmp = (v < 1) ? 1 : v;
 806 
 807         if (pageIncrement == tmp) {
 808             return;
 809         }
 810         pageIncrement = tmp;
 811 
 812         ScrollbarPeer peer = (ScrollbarPeer)this.peer;
 813         if (peer != null) {
 814             peer.setPageIncrement(pageIncrement);
 815         }
 816     }
 817 
 818     /**
 819      * Gets the block increment of this scroll bar.
 820      * <p>
 821      * The block increment is the value that is added or subtracted
 822      * when the user activates the block increment area of the
 823      * scroll bar, generally through a mouse or keyboard gesture
 824      * that the scroll bar receives as an adjustment event.
 825      * The block increment must be greater than zero.
 826      *
 827      * @return      the block increment of this scroll bar
 828      * @see         java.awt.Scrollbar#setBlockIncrement
 829      * @since       JDK1.1
 830      */
 831     public int getBlockIncrement() {
 832         return getPageIncrement();
 833     }
 834 
 835     /**
 836      * @deprecated As of JDK version 1.1,
 837      * replaced by <code>getBlockIncrement()</code>.
 838      */
 839     @Deprecated
 840     public int getPageIncrement() {
 841         return pageIncrement;
 842     }
 843 
 844     /**
 845      * Sets the values of four properties for this scroll bar:
 846      * <code>value</code>, <code>visibleAmount</code>,
 847      * <code>minimum</code>, and <code>maximum</code>.
 848      * If the values supplied for these properties are inconsistent
 849      * or incorrect, they will be changed to ensure consistency.


 955                     ((oldValue) ? AccessibleState.BUSY : null),
 956                     ((b) ? AccessibleState.BUSY : null));
 957         }
 958     }
 959 
 960 
 961 
 962     /**
 963      * Adds the specified adjustment listener to receive instances of
 964      * <code>AdjustmentEvent</code> from this scroll bar.
 965      * If l is <code>null</code>, no exception is thrown and no
 966      * action is performed.
 967      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
 968      * >AWT Threading Issues</a> for details on AWT's threading model.
 969      *
 970      * @param        l the adjustment listener
 971      * @see          #removeAdjustmentListener
 972      * @see          #getAdjustmentListeners
 973      * @see          java.awt.event.AdjustmentEvent
 974      * @see          java.awt.event.AdjustmentListener
 975      * @since        JDK1.1
 976      */
 977     public synchronized void addAdjustmentListener(AdjustmentListener l) {
 978         if (l == null) {
 979             return;
 980         }
 981         adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
 982         newEventsOnly = true;
 983     }
 984 
 985     /**
 986      * Removes the specified adjustment listener so that it no longer
 987      * receives instances of <code>AdjustmentEvent</code> from this scroll bar.
 988      * If l is <code>null</code>, no exception is thrown and no action
 989      * is performed.
 990      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
 991      * >AWT Threading Issues</a> for details on AWT's threading model.
 992      *
 993      * @param           l    the adjustment listener
 994      * @see             #addAdjustmentListener
 995      * @see             #getAdjustmentListeners
 996      * @see             java.awt.event.AdjustmentEvent
 997      * @see             java.awt.event.AdjustmentListener
 998      * @since           JDK1.1
 999      */
1000     public synchronized void removeAdjustmentListener(AdjustmentListener l) {
1001         if (l == null) {
1002             return;
1003         }
1004         adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
1005     }
1006 
1007     /**
1008      * Returns an array of all the adjustment listeners
1009      * registered on this scrollbar.
1010      *
1011      * @return all of this scrollbar's <code>AdjustmentListener</code>s
1012      *         or an empty array if no adjustment
1013      *         listeners are currently registered
1014      * @see             #addAdjustmentListener
1015      * @see             #removeAdjustmentListener
1016      * @see             java.awt.event.AdjustmentEvent
1017      * @see             java.awt.event.AdjustmentListener
1018      * @since 1.4


1069                 return true;
1070             }
1071             return false;
1072         }
1073         return super.eventEnabled(e);
1074     }
1075 
1076     /**
1077      * Processes events on this scroll bar. If the event is an
1078      * instance of <code>AdjustmentEvent</code>, it invokes the
1079      * <code>processAdjustmentEvent</code> method.
1080      * Otherwise, it invokes its superclass's
1081      * <code>processEvent</code> method.
1082      * <p>Note that if the event parameter is <code>null</code>
1083      * the behavior is unspecified and may result in an
1084      * exception.
1085      *
1086      * @param        e the event
1087      * @see          java.awt.event.AdjustmentEvent
1088      * @see          java.awt.Scrollbar#processAdjustmentEvent
1089      * @since        JDK1.1
1090      */
1091     protected void processEvent(AWTEvent e) {
1092         if (e instanceof AdjustmentEvent) {
1093             processAdjustmentEvent((AdjustmentEvent)e);
1094             return;
1095         }
1096         super.processEvent(e);
1097     }
1098 
1099     /**
1100      * Processes adjustment events occurring on this
1101      * scrollbar by dispatching them to any registered
1102      * <code>AdjustmentListener</code> objects.
1103      * <p>
1104      * This method is not called unless adjustment events are
1105      * enabled for this component. Adjustment events are enabled
1106      * when one of the following occurs:
1107      * <ul>
1108      * <li>An <code>AdjustmentListener</code> object is registered
1109      * via <code>addAdjustmentListener</code>.
1110      * <li>Adjustment events are enabled via <code>enableEvents</code>.
1111      * </ul>
1112      * <p>Note that if the event parameter is <code>null</code>
1113      * the behavior is unspecified and may result in an
1114      * exception.
1115      *
1116      * @param       e the adjustment event
1117      * @see         java.awt.event.AdjustmentEvent
1118      * @see         java.awt.event.AdjustmentListener
1119      * @see         java.awt.Scrollbar#addAdjustmentListener
1120      * @see         java.awt.Component#enableEvents
1121      * @since       JDK1.1
1122      */
1123     protected void processAdjustmentEvent(AdjustmentEvent e) {
1124         AdjustmentListener listener = adjustmentListener;
1125         if (listener != null) {
1126             listener.adjustmentValueChanged(e);
1127         }
1128     }
1129 
1130     /**
1131      * Returns a string representing the state of this <code>Scrollbar</code>.
1132      * This method is intended to be used only for debugging purposes, and the
1133      * content and format of the returned string may vary between
1134      * implementations. The returned string may be empty but may not be
1135      * <code>null</code>.
1136      *
1137      * @return      the parameter string of this scroll bar
1138      */
1139     protected String paramString() {
1140         return super.paramString() +
1141             ",val=" + value +




 144  * <code>Event.SCROLL_LINE_UP</code>
 145  * <li><code>AdjustmentEvent.UNIT_DECREMENT</code> replaces
 146  * <code>Event.SCROLL_LINE_DOWN</code>
 147  * <li><code>AdjustmentEvent.BLOCK_INCREMENT</code> replaces
 148  * <code>Event.SCROLL_PAGE_UP</code>
 149  * <li><code>AdjustmentEvent.BLOCK_DECREMENT</code> replaces
 150  * <code>Event.SCROLL_PAGE_DOWN</code>
 151  * </ul>
 152  * <p>
 153  * <b>Note</b>: We recommend using a <code>Scrollbar</code>
 154  * for value selection only.  If you want to implement
 155  * a scrollable component inside a container, we recommend you use
 156  * a {@link ScrollPane ScrollPane}. If you use a
 157  * <code>Scrollbar</code> for this purpose, you are likely to
 158  * encounter issues with painting, key handling, sizing and
 159  * positioning.
 160  *
 161  * @author      Sami Shaio
 162  * @see         java.awt.event.AdjustmentEvent
 163  * @see         java.awt.event.AdjustmentListener
 164  * @since       1.0
 165  */
 166 public class Scrollbar extends Component implements Adjustable, Accessible {
 167 
 168     /**
 169      * A constant that indicates a horizontal scroll bar.
 170      */
 171     public static final int     HORIZONTAL = 0;
 172 
 173     /**
 174      * A constant that indicates a vertical scroll bar.
 175      */
 176     public static final int     VERTICAL   = 1;
 177 
 178     /**
 179      * The value of the <code>Scrollbar</code>.
 180      * This property must be greater than or equal to <code>minimum</code>
 181      * and less than or equal to
 182      * <code>maximum - visibleAmount</code>
 183      *
 184      * @serial


 443      *
 444      * @return    the orientation of this scroll bar, either
 445      *               <code>Scrollbar.HORIZONTAL</code> or
 446      *               <code>Scrollbar.VERTICAL</code>
 447      * @see       java.awt.Scrollbar#setOrientation
 448      */
 449     public int getOrientation() {
 450         return orientation;
 451     }
 452 
 453     /**
 454      * Sets the orientation for this scroll bar.
 455      *
 456      * @param orientation  the orientation of this scroll bar, either
 457      *               <code>Scrollbar.HORIZONTAL</code> or
 458      *               <code>Scrollbar.VERTICAL</code>
 459      * @see       java.awt.Scrollbar#getOrientation
 460      * @exception   IllegalArgumentException  if the value supplied
 461      *                   for <code>orientation</code> is not a
 462      *                   legal value
 463      * @since     1.1
 464      */
 465     public void setOrientation(int orientation) {
 466         synchronized (getTreeLock()) {
 467             if (orientation == this.orientation) {
 468                 return;
 469             }
 470             switch (orientation) {
 471                 case HORIZONTAL:
 472                 case VERTICAL:
 473                     this.orientation = orientation;
 474                     break;
 475                 default:
 476                     throw new IllegalArgumentException("illegal scrollbar orientation");
 477             }
 478             /* Create a new peer with the specified orientation. */
 479             if (peer != null) {
 480                 removeNotify();
 481                 addNotify();
 482                 invalidate();
 483             }


 549      * <p>
 550      * When <code>setMinimum</code> is called, the minimum value
 551      * is changed, and other values (including the maximum, the
 552      * visible amount, and the current scroll bar value)
 553      * are changed to be consistent with the new minimum.
 554      * <p>
 555      * Normally, a program should change a scroll bar's minimum
 556      * value only by calling <code>setValues</code>.
 557      * The <code>setValues</code> method simultaneously
 558      * and synchronously sets the minimum, maximum, visible amount,
 559      * and value properties of a scroll bar, so that they are
 560      * mutually consistent.
 561      * <p>
 562      * Note that setting the minimum value to <code>Integer.MAX_VALUE</code>
 563      * will result in the new minimum value being set to
 564      * <code>Integer.MAX_VALUE - 1</code>.
 565      *
 566      * @param       newMinimum   the new minimum value for this scroll bar
 567      * @see         java.awt.Scrollbar#setValues
 568      * @see         java.awt.Scrollbar#setMaximum
 569      * @since       1.1
 570      */
 571     public void setMinimum(int newMinimum) {
 572         // No checks are necessary in this method since minimum is
 573         // the first variable checked in the setValues function.
 574 
 575         // Use setValues so that a consistent policy relating
 576         // minimum, maximum, visible amount, and value is enforced.
 577         setValues(value, visibleAmount, newMinimum, maximum);
 578     }
 579 
 580     /**
 581      * Gets the maximum value of this scroll bar.
 582      *
 583      * @return      the maximum value of this scroll bar
 584      * @see         java.awt.Scrollbar#getValue
 585      * @see         java.awt.Scrollbar#getMinimum
 586      */
 587     public int getMaximum() {
 588         return maximum;
 589     }


 594      * When <code>setMaximum</code> is called, the maximum value
 595      * is changed, and other values (including the minimum, the
 596      * visible amount, and the current scroll bar value)
 597      * are changed to be consistent with the new maximum.
 598      * <p>
 599      * Normally, a program should change a scroll bar's maximum
 600      * value only by calling <code>setValues</code>.
 601      * The <code>setValues</code> method simultaneously
 602      * and synchronously sets the minimum, maximum, visible amount,
 603      * and value properties of a scroll bar, so that they are
 604      * mutually consistent.
 605      * <p>
 606      * Note that setting the maximum value to <code>Integer.MIN_VALUE</code>
 607      * will result in the new maximum value being set to
 608      * <code>Integer.MIN_VALUE + 1</code>.
 609      *
 610      * @param       newMaximum   the new maximum value
 611      *                     for this scroll bar
 612      * @see         java.awt.Scrollbar#setValues
 613      * @see         java.awt.Scrollbar#setMinimum
 614      * @since       1.1
 615      */
 616     public void setMaximum(int newMaximum) {
 617         // minimum is checked first in setValues, so we need to
 618         // enforce minimum and maximum checks here.
 619         if (newMaximum == Integer.MIN_VALUE) {
 620             newMaximum = Integer.MIN_VALUE + 1;
 621         }
 622 
 623         if (minimum >= newMaximum) {
 624             minimum = newMaximum - 1;
 625         }
 626 
 627         // Use setValues so that a consistent policy relating
 628         // minimum, maximum, visible amount, and value is enforced.
 629         setValues(value, visibleAmount, minimum, newMaximum);
 630     }
 631 
 632     /**
 633      * Gets the visible amount of this scroll bar.
 634      * <p>
 635      * When a scroll bar is used to select a range of values,
 636      * the visible amount is used to represent the range of values
 637      * that are currently visible.  The size of the scroll bar's
 638      * bubble (also called a thumb or scroll box), usually gives a
 639      * visual representation of the relationship of the visible
 640      * amount to the range of the scroll bar.
 641      * Note that depending on platform, the value of the visible amount property
 642      * may not be visually indicated by the size of the bubble.
 643      * <p>
 644      * The scroll bar's bubble may not be displayed when it is not
 645      * moveable (e.g. when it takes up the entire length of the
 646      * scroll bar's track, or when the scroll bar is disabled).
 647      * Whether the bubble is displayed or not will not affect
 648      * the value returned by <code>getVisibleAmount</code>.
 649      *
 650      * @return      the visible amount of this scroll bar
 651      * @see         java.awt.Scrollbar#setVisibleAmount
 652      * @since       1.1
 653      */
 654     public int getVisibleAmount() {
 655         return getVisible();
 656     }
 657 
 658     /**
 659      * @deprecated As of JDK version 1.1,
 660      * replaced by <code>getVisibleAmount()</code>.
 661      */
 662     @Deprecated
 663     public int getVisible() {
 664         return visibleAmount;
 665     }
 666 
 667     /**
 668      * Sets the visible amount of this scroll bar.
 669      * <p>
 670      * When a scroll bar is used to select a range of values,
 671      * the visible amount is used to represent the range of values
 672      * that are currently visible.  The size of the scroll bar's


 680      * moveable (e.g. when it takes up the entire length of the
 681      * scroll bar's track, or when the scroll bar is disabled).
 682      * Whether the bubble is displayed or not will not affect
 683      * the value returned by <code>getVisibleAmount</code>.
 684      * <p>
 685      * If the visible amount supplied is less than <code>one</code>
 686      * or greater than the current <code>maximum - minimum</code>,
 687      * then either <code>one</code> or <code>maximum - minimum</code>
 688      * is substituted, as appropriate.
 689      * <p>
 690      * Normally, a program should change a scroll bar's
 691      * value only by calling <code>setValues</code>.
 692      * The <code>setValues</code> method simultaneously
 693      * and synchronously sets the minimum, maximum, visible amount,
 694      * and value properties of a scroll bar, so that they are
 695      * mutually consistent.
 696      *
 697      * @param       newAmount the new visible amount
 698      * @see         java.awt.Scrollbar#getVisibleAmount
 699      * @see         java.awt.Scrollbar#setValues
 700      * @since       1.1
 701      */
 702     public void setVisibleAmount(int newAmount) {
 703         // Use setValues so that a consistent policy relating
 704         // minimum, maximum, visible amount, and value is enforced.
 705         setValues(value, newAmount, minimum, maximum);
 706     }
 707 
 708     /**
 709      * Sets the unit increment for this scroll bar.
 710      * <p>
 711      * The unit increment is the value that is added or subtracted
 712      * when the user activates the unit increment area of the
 713      * scroll bar, generally through a mouse or keyboard gesture
 714      * that the scroll bar receives as an adjustment event.
 715      * The unit increment must be greater than zero.
 716      * Attepts to set the unit increment to a value lower than 1
 717      * will result in a value of 1 being set.
 718      * <p>
 719      * In some operating systems, this property
 720      * can be ignored by the underlying controls.
 721      *
 722      * @param        v  the amount by which to increment or decrement
 723      *                         the scroll bar's value
 724      * @see          java.awt.Scrollbar#getUnitIncrement
 725      * @since        1.1
 726      */
 727     public void setUnitIncrement(int v) {
 728         setLineIncrement(v);
 729     }
 730 
 731     /**
 732      * @deprecated As of JDK version 1.1,
 733      * replaced by <code>setUnitIncrement(int)</code>.
 734      */
 735     @Deprecated
 736     public synchronized void setLineIncrement(int v) {
 737         int tmp = (v < 1) ? 1 : v;
 738 
 739         if (lineIncrement == tmp) {
 740             return;
 741         }
 742         lineIncrement = tmp;
 743 
 744         ScrollbarPeer peer = (ScrollbarPeer)this.peer;
 745         if (peer != null) {
 746             peer.setLineIncrement(lineIncrement);
 747         }
 748     }
 749 
 750     /**
 751      * Gets the unit increment for this scrollbar.
 752      * <p>
 753      * The unit increment is the value that is added or subtracted
 754      * when the user activates the unit increment area of the
 755      * scroll bar, generally through a mouse or keyboard gesture
 756      * that the scroll bar receives as an adjustment event.
 757      * The unit increment must be greater than zero.
 758      * <p>
 759      * In some operating systems, this property
 760      * can be ignored by the underlying controls.
 761      *
 762      * @return      the unit increment of this scroll bar
 763      * @see         java.awt.Scrollbar#setUnitIncrement
 764      * @since       1.1
 765      */
 766     public int getUnitIncrement() {
 767         return getLineIncrement();
 768     }
 769 
 770     /**
 771      * @deprecated As of JDK version 1.1,
 772      * replaced by <code>getUnitIncrement()</code>.
 773      */
 774     @Deprecated
 775     public int getLineIncrement() {
 776         return lineIncrement;
 777     }
 778 
 779     /**
 780      * Sets the block increment for this scroll bar.
 781      * <p>
 782      * The block increment is the value that is added or subtracted
 783      * when the user activates the block increment area of the
 784      * scroll bar, generally through a mouse or keyboard gesture
 785      * that the scroll bar receives as an adjustment event.
 786      * The block increment must be greater than zero.
 787      * Attepts to set the block increment to a value lower than 1
 788      * will result in a value of 1 being set.
 789      *
 790      * @param        v  the amount by which to increment or decrement
 791      *                         the scroll bar's value
 792      * @see          java.awt.Scrollbar#getBlockIncrement
 793      * @since        1.1
 794      */
 795     public void setBlockIncrement(int v) {
 796         setPageIncrement(v);
 797     }
 798 
 799     /**
 800      * @deprecated As of JDK version 1.1,
 801      * replaced by <code>setBlockIncrement()</code>.
 802      */
 803     @Deprecated
 804     public synchronized void setPageIncrement(int v) {
 805         int tmp = (v < 1) ? 1 : v;
 806 
 807         if (pageIncrement == tmp) {
 808             return;
 809         }
 810         pageIncrement = tmp;
 811 
 812         ScrollbarPeer peer = (ScrollbarPeer)this.peer;
 813         if (peer != null) {
 814             peer.setPageIncrement(pageIncrement);
 815         }
 816     }
 817 
 818     /**
 819      * Gets the block increment of this scroll bar.
 820      * <p>
 821      * The block increment is the value that is added or subtracted
 822      * when the user activates the block increment area of the
 823      * scroll bar, generally through a mouse or keyboard gesture
 824      * that the scroll bar receives as an adjustment event.
 825      * The block increment must be greater than zero.
 826      *
 827      * @return      the block increment of this scroll bar
 828      * @see         java.awt.Scrollbar#setBlockIncrement
 829      * @since       1.1
 830      */
 831     public int getBlockIncrement() {
 832         return getPageIncrement();
 833     }
 834 
 835     /**
 836      * @deprecated As of JDK version 1.1,
 837      * replaced by <code>getBlockIncrement()</code>.
 838      */
 839     @Deprecated
 840     public int getPageIncrement() {
 841         return pageIncrement;
 842     }
 843 
 844     /**
 845      * Sets the values of four properties for this scroll bar:
 846      * <code>value</code>, <code>visibleAmount</code>,
 847      * <code>minimum</code>, and <code>maximum</code>.
 848      * If the values supplied for these properties are inconsistent
 849      * or incorrect, they will be changed to ensure consistency.


 955                     ((oldValue) ? AccessibleState.BUSY : null),
 956                     ((b) ? AccessibleState.BUSY : null));
 957         }
 958     }
 959 
 960 
 961 
 962     /**
 963      * Adds the specified adjustment listener to receive instances of
 964      * <code>AdjustmentEvent</code> from this scroll bar.
 965      * If l is <code>null</code>, no exception is thrown and no
 966      * action is performed.
 967      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
 968      * >AWT Threading Issues</a> for details on AWT's threading model.
 969      *
 970      * @param        l the adjustment listener
 971      * @see          #removeAdjustmentListener
 972      * @see          #getAdjustmentListeners
 973      * @see          java.awt.event.AdjustmentEvent
 974      * @see          java.awt.event.AdjustmentListener
 975      * @since        1.1
 976      */
 977     public synchronized void addAdjustmentListener(AdjustmentListener l) {
 978         if (l == null) {
 979             return;
 980         }
 981         adjustmentListener = AWTEventMulticaster.add(adjustmentListener, l);
 982         newEventsOnly = true;
 983     }
 984 
 985     /**
 986      * Removes the specified adjustment listener so that it no longer
 987      * receives instances of <code>AdjustmentEvent</code> from this scroll bar.
 988      * If l is <code>null</code>, no exception is thrown and no action
 989      * is performed.
 990      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
 991      * >AWT Threading Issues</a> for details on AWT's threading model.
 992      *
 993      * @param           l    the adjustment listener
 994      * @see             #addAdjustmentListener
 995      * @see             #getAdjustmentListeners
 996      * @see             java.awt.event.AdjustmentEvent
 997      * @see             java.awt.event.AdjustmentListener
 998      * @since           1.1
 999      */
1000     public synchronized void removeAdjustmentListener(AdjustmentListener l) {
1001         if (l == null) {
1002             return;
1003         }
1004         adjustmentListener = AWTEventMulticaster.remove(adjustmentListener, l);
1005     }
1006 
1007     /**
1008      * Returns an array of all the adjustment listeners
1009      * registered on this scrollbar.
1010      *
1011      * @return all of this scrollbar's <code>AdjustmentListener</code>s
1012      *         or an empty array if no adjustment
1013      *         listeners are currently registered
1014      * @see             #addAdjustmentListener
1015      * @see             #removeAdjustmentListener
1016      * @see             java.awt.event.AdjustmentEvent
1017      * @see             java.awt.event.AdjustmentListener
1018      * @since 1.4


1069                 return true;
1070             }
1071             return false;
1072         }
1073         return super.eventEnabled(e);
1074     }
1075 
1076     /**
1077      * Processes events on this scroll bar. If the event is an
1078      * instance of <code>AdjustmentEvent</code>, it invokes the
1079      * <code>processAdjustmentEvent</code> method.
1080      * Otherwise, it invokes its superclass's
1081      * <code>processEvent</code> method.
1082      * <p>Note that if the event parameter is <code>null</code>
1083      * the behavior is unspecified and may result in an
1084      * exception.
1085      *
1086      * @param        e the event
1087      * @see          java.awt.event.AdjustmentEvent
1088      * @see          java.awt.Scrollbar#processAdjustmentEvent
1089      * @since        1.1
1090      */
1091     protected void processEvent(AWTEvent e) {
1092         if (e instanceof AdjustmentEvent) {
1093             processAdjustmentEvent((AdjustmentEvent)e);
1094             return;
1095         }
1096         super.processEvent(e);
1097     }
1098 
1099     /**
1100      * Processes adjustment events occurring on this
1101      * scrollbar by dispatching them to any registered
1102      * <code>AdjustmentListener</code> objects.
1103      * <p>
1104      * This method is not called unless adjustment events are
1105      * enabled for this component. Adjustment events are enabled
1106      * when one of the following occurs:
1107      * <ul>
1108      * <li>An <code>AdjustmentListener</code> object is registered
1109      * via <code>addAdjustmentListener</code>.
1110      * <li>Adjustment events are enabled via <code>enableEvents</code>.
1111      * </ul>
1112      * <p>Note that if the event parameter is <code>null</code>
1113      * the behavior is unspecified and may result in an
1114      * exception.
1115      *
1116      * @param       e the adjustment event
1117      * @see         java.awt.event.AdjustmentEvent
1118      * @see         java.awt.event.AdjustmentListener
1119      * @see         java.awt.Scrollbar#addAdjustmentListener
1120      * @see         java.awt.Component#enableEvents
1121      * @since       1.1
1122      */
1123     protected void processAdjustmentEvent(AdjustmentEvent e) {
1124         AdjustmentListener listener = adjustmentListener;
1125         if (listener != null) {
1126             listener.adjustmentValueChanged(e);
1127         }
1128     }
1129 
1130     /**
1131      * Returns a string representing the state of this <code>Scrollbar</code>.
1132      * This method is intended to be used only for debugging purposes, and the
1133      * content and format of the returned string may vary between
1134      * implementations. The returned string may be empty but may not be
1135      * <code>null</code>.
1136      *
1137      * @return      the parameter string of this scroll bar
1138      */
1139     protected String paramString() {
1140         return super.paramString() +
1141             ",val=" + value +