Class RangeSlider

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

    public class RangeSlider
    extends JSlider
    An extension of JSlider to select a range of values using two thumb controls. The thumb controls are used to select the lower and upper value of a range with predetermined minimum and maximum values.

    Note that RangeSlider makes use of the default BoundedRangeModel, which supports an inner range defined by a value and an extent. The upper value returned by RangeSlider is simply the lower value plus the extent.

    This is copied from https://github.com/ernieyu/Swing-range-slider with the following changes:

    • The slider thumbs push each other. That is, the upper thumb can be dragged below the lower thumb, and it will drag the lower thumb with it, and vice versa
    • The setRange(int, int) method was added, which sets both the lower and upper values simultaneously.

     =============================================================================
    
     The MIT License Copyright (c) 2010 Ernest Yu. All rights reserved.
    
     Permission is hereby granted, free of charge, to any person obtaining a copy
     of this software and associated documentation files (the "Software"), to deal
     in the Software without restriction, including without limitation the rights
     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     copies of the Software, and to permit persons to whom the Software is
     furnished to do so, subject to the following conditions:
    
     The above copyright notice and this permission notice shall be included in
     all copies or substantial portions of the Software.
    
     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     SOFTWARE.
     
    See Also:
    Serialized Form
    • Constructor Detail

      • RangeSlider

        public RangeSlider()
        Constructs a RangeSlider with default minimum and maximum values of 0 and 100.
      • RangeSlider

        public RangeSlider​(int min,
                           int max)
        Constructs a RangeSlider with the specified default minimum and maximum values.
    • Method Detail

      • updateUI

        public void updateUI()
        Overrides the superclass method to install the UI delegate to draw two thumbs.
        Overrides:
        updateUI in class JSlider
      • getValue

        public int getValue()
        Returns the lower value in the range.
        Overrides:
        getValue in class JSlider
      • setValue

        public void setValue​(int value)
        Sets the lower value in the range.
        Overrides:
        setValue in class JSlider
      • getUpperValue

        public int getUpperValue()
        Returns the upper value in the range.
      • setUpperValue

        public void setUpperValue​(int value)
        Sets the upper value in the range.
      • setRange

        public void setRange​(int lower,
                             int upper)
        Sets both the lower and upper values in the range.