Class RangeSliderUtil


  • public class RangeSliderUtil
    extends java.lang.Object
    Utility classes for JSlider components that can define a range. The JSlider API (especially BoundedRangeModel) is capable of working with (2-element) ranges rather than single values. The Swing JSlider component only has a single value, but there are external implementations that provide the range functionality. Since the JSlider API is up to the job, we don't define a new interface here, but the methods here let you construct and use range-capable JSlider instances.
    Since:
    10 Mar 2017
    Author:
    Mark Taylor
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.swing.JSlider createRangeSlider​(int imin, int imax)
      Constructs a range-capable slider instance.
      static int[] getSliderRange​(javax.swing.JSlider slider)
      Returns the range represented by a range-capable slider.
      static void setSliderRange​(javax.swing.JSlider slider, int ilo, int ihi)
      Sets the range represented by a range-capable slider.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createRangeSlider

        public static javax.swing.JSlider createRangeSlider​(int imin,
                                                            int imax)
        Constructs a range-capable slider instance. If possible, an instance of com.jidesoft.swing.RangeSlider is returned, but if that fails it falls back to the (uglier, less capable) local variant.

        JIDE failure can happen in one of (at least?) two ways. First, if the current Look&Feel is not supported by the JIDE component, which doesn't support for example Nimbus(?). Second, if the JIDE class refers to a JRE class that is not present; this appears to happen on OSX Java 10, where a java.lang.ClassNotFoundException is reported for com.sun.java.swing.plaf.windows.WindowsLookAndFeel, which has apparently been withdrawn in that environment. Tweaking the JIDE source to avoid looking for that class, or to fail more gracefully, or upgrading to a later JIDE-OSS version, could probably work to avoid the latter problem. However, there seems to be a lot of UI magic in the JIDE component (probably unavoidable to get full L&F integration), so it's wise to have a fallback.

        Parameters:
        imin - minimum value
        imax - maximum value
        Returns:
        range slider
      • getSliderRange

        public static int[] getSliderRange​(javax.swing.JSlider slider)
        Returns the range represented by a range-capable slider.
        Parameters:
        slider - range-capable slider (presumably created by this class)
        Returns:
        2-element (lo,hi) array
      • setSliderRange

        public static void setSliderRange​(javax.swing.JSlider slider,
                                          int ilo,
                                          int ihi)
        Sets the range represented by a range-capable slider.
        Parameters:
        slider - range-capable slider (presumably created by this class)
        ilo - range lower value
        ihi - range upper value