Class RangeSlider

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class RangeSlider extends JPanel
A simple utility component that wraps a JSlider and an optional label that displays the current slider value.

The RangeSlider supports two callback hooks:

This makes the component suitable for interactive UI (continuous updates) and more expensive model / rendering updates (on final change).
See Also:
  • Constructor Details

    • RangeSlider

      public RangeSlider(int min, int max, int defaultVal)
      Constructs a slider with no tick marks and a visible value label.
    • RangeSlider

      public RangeSlider(int min, int max, int defaultVal, boolean showValue)
      Constructs a slider with optional value label and no ticks.
      Parameters:
      showValue - whether the current numeric value is shown
    • RangeSlider

      public RangeSlider(int min, int max, int defaultVal, int majorTick, int minorTick)
      Constructs a slider with ticks and a visible value label.
    • RangeSlider

      public RangeSlider(int min, int max, int defaultVal, int majorTick, int minorTick, boolean showValue)
      Full constructor with complete customization.

      Tick spacing is applied conditionally and independently:

      • Major ticks are set only if 0 < majorTick < max; otherwise major ticks are silently omitted (not clamped to a valid value).
      • Minor ticks are set only if 0 < minorTick < majorTick, comparing against the parameter majorTick — not against whether major ticks actually ended up enabled. So it is possible to get minor ticks without major ticks, e.g. if majorTick >= max (major ticks omitted) but 0 < minorTick < majorTick still holds.
      Parameters:
      majorTick - major tick spacing; 0 (or >= max) for none
      minorTick - minor tick spacing; 0 (or >= majorTick) for none
      Throws:
      IllegalArgumentException - if min > max, if defaultVal is outside [min, max], or if either tick spacing is negative
  • Method Details

    • setOnChange

      public void setOnChange(Consumer<Integer> callback)
      Registers a callback for continuous change notifications.
    • setOnFinalChange

      public void setOnFinalChange(Consumer<Integer> callback)
      Registers a callback for final change notifications.
    • getValue

      public int getValue()
      Returns the current slider value.
    • setValue

      public void setValue(int value)
      Programmatically sets the slider value.
    • getMinimum

      public int getMinimum()
      Returns the slider's minimum value.
    • getMaximum

      public int getMaximum()
      Returns the slider's maximum value.
    • getSlider

      public JSlider getSlider()
      Returns the underlying JSlider for users who need to add custom label tables or further tweak the component.