Class SliderSpinner

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class SliderSpinner extends JPanel
A combined component featuring a JSpinner and a JSlider that stay in sync. It uses JGoodies FormLayout for precise positioning.
Author:
anahata
See Also:
  • Field Details

    • spinner

      private final JSpinner spinner
      The underlying spinner.
    • slider

      private final JSlider slider
      The underlying slider.
    • scale

      private final double scale
      The scale factor between the spinner value and the slider value (slider = spinner * scale).
    • isAdjusting

      private boolean isAdjusting
      Flag to prevent infinite recursion during sync.
  • Constructor Details

    • SliderSpinner

      public SliderSpinner(SpinnerNumberModel model, int sliderMin, int sliderMax, double scale)
      Constructs a new SliderSpinner.
      Parameters:
      model - The SpinnerNumberModel to use.
      sliderMin - The minimum value for the slider.
      sliderMax - The maximum value for the slider.
      scale - The scale factor between the spinner value and the slider value.
  • Method Details

    • getValue

      public Object getValue()
      Gets the current value from the spinner.
      Returns:
      The value.
    • setValue

      public void setValue(Object value)
      Sets the value of the spinner (and thus the slider).
      Parameters:
      value - The new value.
    • getSpinner

      public JSpinner getSpinner()
      Gets the underlying JSpinner.
      Returns:
      The spinner.
    • getSlider

      public JSlider getSlider()
      Gets the underlying JSlider.
      Returns:
      The slider.
    • addChangeListener

      public void addChangeListener(ChangeListener listener)
      Adds a ChangeListener to the underlying spinner.
      Parameters:
      listener - The listener to add.
    • setEnabled

      public void setEnabled(boolean enabled)

      Overridden to synchronize the enabled state across both the spinner and the slider sub-components.

      Overrides:
      setEnabled in class JComponent