Module java.desktop
Package javax.swing

Class JScrollBar

  • All Implemented Interfaces:
    Adjustable, ImageObserver, MenuContainer, Serializable, Accessible
    Direct Known Subclasses:
    JScrollPane.ScrollBar

    @JavaBean(defaultProperty="UI",
              description="A component that helps determine the visible content range of an area.")
    public class JScrollBar
    extends JComponent
    implements Adjustable, Accessible
    An implementation of a scrollbar. The user positions the knob in the scrollbar to determine the contents of the viewing area. The program typically adjusts the display so that the end of the scrollbar represents the end of the displayable contents, or 100% of the contents. The start of the scrollbar is the beginning of the displayable contents, or 0%. The position of the knob within those bounds then translates to the corresponding percentage of the displayable contents.

    Typically, as the position of the knob in the scrollbar changes a corresponding change is made to the position of the JViewport on the underlying view, changing the contents of the JViewport.

    Warning: Swing is not thread safe. For more information see Swing's Threading Policy.

    Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.

    Since:
    1.2
    See Also:
    JScrollPane, Serialized Form
    • Constructor Detail

      • JScrollBar

        public JScrollBar​(int orientation,
                          int value,
                          int extent,
                          int min,
                          int max)
        Creates a scrollbar with the specified orientation, value, extent, minimum, and maximum. The "extent" is the size of the viewable area. It is also known as the "visible amount".

        Note: Use setBlockIncrement to set the block increment to a size slightly smaller than the view's extent. That way, when the user jumps the knob to an adjacent position, one or two lines of the original contents remain in view.

        Parameters:
        orientation - an orientation of the JScrollBar
        value - an int giving the current value
        extent - an int giving the amount by which the value can "jump"
        min - an int giving the minimum value
        max - an int giving the maximum value
        Throws:
        IllegalArgumentException - if orientation is not one of VERTICAL, HORIZONTAL
        See Also:
        setOrientation(int), setValue(int), setVisibleAmount(int), setMinimum(int), setMaximum(int)
      • JScrollBar

        public JScrollBar​(int orientation)
        Creates a scrollbar with the specified orientation and the following initial values:
         minimum = 0
         maximum = 100
         value = 0
         extent = 10
         
        Parameters:
        orientation - an orientation of the JScrollBar
      • JScrollBar

        public JScrollBar()
        Creates a vertical scrollbar with the following initial values:
         minimum = 0
         maximum = 100
         value = 0
         extent = 10