Class SpinSlider

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class SpinSlider extends JPanel
SpinSlider implements a combination of horizontal slider and input text field (Spinner). The slider and the spinner are synchronized automatically.
See Also:
  • Constructor Details

  • Method Details

    • getValue

      public Number getValue()
      Returns current value reflecting the slider's position. Even if the postponed synchronization is turned on (see setContinuousSync(boolean)), the correct value is computed and returned anyway.

      Based on the type, the return value is

      • INTEGER: An Integer from set range.
      • DOUBLE: An Double from set range.
      • PERCENTAGE: An Integer between 0 and 100.

      Usage:

      • After initDouble(): double var = (Double) spinSlider.getValue().
      • After initInteger(): double var = (Integer) spinSlider.getValue().
      • After initPercentage(): double var = (Integer) spinSlider.getValue().
      Returns:
      Current value
    • setValue

      public void setValue(Number value)
      Sets the value.
      Parameters:
      value - A new value
    • initInteger

      public void initInteger(int value, int min, int max, int stepSize)
      Initializes this spin-slider to integers. Removed all listeners!
      Parameters:
      value - Initial value
      min - Minimum value
      max - Maximum value
      stepSize - Spin step size
    • initDouble

      public void initDouble(double value, double min, double max, int fractionDigits)
      Initializes this spin-slider to doubles. Removes all listeners!
      Parameters:
      value - Initial value
      min - Minimum value
      max - Maximum value
      fractionDigits - precision of floating numbers, i.e., the number of digits allowed after the floating dot. Must be bigger than zero.
    • initPercentage

      public void initPercentage(int value)
      Initializes this spin-slider to percents.
      Parameters:
      value - Initial value between 0 and 100.
    • initPercentage

      public void initPercentage(int value, int min, int max)
      Initializes this spin-slider to percents in given range.
      Parameters:
      value - Initial value between 0 and 100.
      min - min value in the range 0..100
      max - max value in the range 0..100
    • setContinuousSync

      public final void setContinuousSync(boolean continuousSync)
      If true, then the spinner is updated continuously during the slider move. Otherwise, the spinner remains unchanged until the mouse key is released.
      Parameters:
      continuousSync - Whether to update the spinner continuously.
    • isContinuousSync

      public boolean isContinuousSync()
      If true, then the spinner is updated continuously during the slider move. Otherwise, the spinner remains unchanged until the mouse key releases.
      Returns:
      true if the slider and the spinner are synchronized continuously.
    • addSpinnerListener

      public void addSpinnerListener(ActionListener listener)
      Be informed when the spinner's value changes. See also setContinuousSync(boolean). Event's source is set to JSpinner. For the double type of the spin-slider, it is DoubleSpinner
      Parameters:
      listener - the action listener to be added
    • addSliderListener

      public void addSliderListener(ActionListener listener)
      Be informed when the slider changes. See also setContinuousSync(boolean). Event's source is set to JSlider
      Parameters:
      listener - the action listener to be added
    • setEnabled

      public void setEnabled(boolean enabled)
      Overrides:
      setEnabled in class JComponent
    • getSpinner

      public JSpinner getSpinner()
    • getSlider

      public JSlider getSlider()
    • initComponents

      protected final void initComponents()
    • setSliderSize

      public void setSliderSize(int size)
      Sets the width of slider.
      Parameters:
      size - slider width