Class Slider

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<Slider,Double>
com.vaadin.flow.component.AbstractSinglePropertyField<Slider,Double>
com.vaadin.flow.component.slider.Slider
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<Slider>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<Slider>, com.vaadin.flow.component.FocusNotifier<Slider>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>,Double>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>,Double>, com.vaadin.flow.component.KeyNotifier, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>,Double>, Serializable

@Tag("vaadin-slider") @NpmPackage(value="@vaadin/slider", version="25.1.0-alpha6") @JsModule("@vaadin/slider/src/vaadin-slider.js") public class Slider extends com.vaadin.flow.component.AbstractSinglePropertyField<Slider,Double>
Slider is an input field that allows the user to select a numeric value within a range by dragging a handle along a track or using arrow keys for precise input.
Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField

    com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue

    com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a Slider with min 0, max 100, and initial value 0.
    Slider(double min, double max, double value)
    Constructs a Slider with the given min, max and initial value.
    Slider(double min, double max, double step, double value)
    Constructs a Slider with the given min, max, step, and initial value.
    Slider(double min, double max, double step, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
    Constructs a Slider with the given min, max, step, initial value, and a value change listener.
    Slider(double min, double max, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
    Constructs a Slider with the given min, max, initial value, and a value change listener.
    Slider(com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
    Constructs a Slider with min 0, max 100, initial value 0, and a value change listener.
    Slider(String label)
    Constructs a Slider with the given label, min 0, max 100, and initial value 0.
    Slider(String label, double min, double max, double value)
    Constructs a Slider with the given label, min, max, and initial value.
    Slider(String label, double min, double max, double step, double value)
    Constructs a Slider with the given label, min, max, step, and initial value.
    Slider(String label, double min, double max, double step, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
    Constructs a Slider with the given label, min, max, step, initial value, and a value change listener.
    Slider(String label, double min, double max, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
    Constructs a Slider with the given label, min, max, initial value, and a value change listener.
    Slider(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
    Constructs a Slider with the given label, min 0, max 100, initial value 0, and a value change listener.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the slider value, setting it to the minimum value.
    double
    Gets the maximum value of the slider.
    double
    Gets the minimum value of the slider.
    double
    Gets the step value of the slider.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    setMax(double max)
    Sets the maximum value of the slider.
    void
    setMin(double min)
    Sets the minimum value of the slider.
    void
    setStep(double step)
    Sets the step value of the slider.
    void
    Sets the value of the slider.
    void
    setValue(Double value, double min, double max)
    Sets the minimum, maximum, and value of the slider atomically.
    void
    setValue(Double value, double min, double max, double step)
    Sets the minimum, maximum, step, and value of the slider atomically.

    Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

    getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent

    Methods inherited from class com.vaadin.flow.component.AbstractField

    addValueChangeListener, bindValue, getEmptyValue, getValue, isEmpty, setModelValue, valueEquals

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    bindEnabled, isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasHelper

    bindHelperText, getHelperComponent, getHelperText, setHelperComponent, setHelperText

    Methods inherited from interface com.vaadin.flow.component.HasLabel

    getLabel, setLabel

    Methods inherited from interface com.vaadin.flow.component.HasSize

    bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipMarkdown, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.HasValidation

    setManualValidation

    Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties

    bindErrorMessage, bindInvalid, getErrorMessage, isInvalid, setErrorMessage, setInvalid

    Methods inherited from interface com.vaadin.flow.component.HasValue

    addValueChangeListener, bindValue, getEmptyValue, getOptionalValue, getValue, isEmpty

    Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

    bindReadOnly, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible

    Methods inherited from interface com.vaadin.flow.component.KeyNotifier

    addKeyDownListener, addKeyDownListener, addKeyPressListener, addKeyPressListener, addKeyUpListener, addKeyUpListener
  • Constructor Details

    • Slider

      public Slider()
      Constructs a Slider with min 0, max 100, and initial value 0.

      The step defaults to 1.

    • Slider

      public Slider(com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
      Constructs a Slider with min 0, max 100, initial value 0, and a value change listener.

      The step defaults to 1.

      Parameters:
      listener - the value change listener
    • Slider

      public Slider(double min, double max, double value)
      Constructs a Slider with the given min, max and initial value.

      The step defaults to 1.

      Parameters:
      min - the minimum value
      max - the maximum value
      value - the initial value
    • Slider

      public Slider(double min, double max, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
      Constructs a Slider with the given min, max, initial value, and a value change listener.

      The step defaults to 1.

      Parameters:
      min - the minimum value
      max - the maximum value
      value - the initial value
      listener - the value change listener
    • Slider

      public Slider(double min, double max, double step, double value)
      Constructs a Slider with the given min, max, step, and initial value.
      Parameters:
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
    • Slider

      public Slider(double min, double max, double step, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
      Constructs a Slider with the given min, max, step, initial value, and a value change listener.
      Parameters:
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
      listener - the value change listener
    • Slider

      public Slider(String label)
      Constructs a Slider with the given label, min 0, max 100, and initial value 0.

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
    • Slider

      public Slider(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
      Constructs a Slider with the given label, min 0, max 100, initial value 0, and a value change listener.

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
      listener - the value change listener
    • Slider

      public Slider(String label, double min, double max, double value)
      Constructs a Slider with the given label, min, max, and initial value.

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      value - the initial value
    • Slider

      public Slider(String label, double min, double max, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
      Constructs a Slider with the given label, min, max, initial value, and a value change listener.
      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      value - the initial value
      listener - the value change listener
    • Slider

      public Slider(String label, double min, double max, double step, double value)
      Constructs a Slider with the given label, min, max, step, and initial value.
      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
    • Slider

      public Slider(String label, double min, double max, double step, double value, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Slider,Double>> listener)
      Constructs a Slider with the given label, min, max, step, initial value, and a value change listener.
      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
      listener - the value change listener
  • Method Details

    • getMin

      public double getMin()
      Gets the minimum value of the slider.
      Returns:
      the minimum value
    • setMin

      public void setMin(double min)
      Sets the minimum value of the slider.

      If the current value is less than the new minimum, it's automatically clamped, which triggers a value change event. To set both the minimum and value explicitly, use the

      invalid reference
      setValue(value, min, max)
      method instead.
      Parameters:
      min - the minimum value
      Throws:
      IllegalArgumentException - if min is greater than the current max
    • getMax

      public double getMax()
      Gets the maximum value of the slider.
      Returns:
      the maximum value
    • setMax

      public void setMax(double max)
      Sets the maximum value of the slider.

      If the current value is greater than the new maximum, it's automatically clamped, which triggers a value change event. To set both the maximum and value explicitly, use the

      invalid reference
      setValue(value, min, max)
      method instead.
      Parameters:
      max - the maximum value
      Throws:
      IllegalArgumentException - if max is less than the current min
    • getStep

      public double getStep()
      Gets the step value of the slider.

      Valid slider values are calculated relative to the minimum value: min, min + step, min + 2*step, etc.

      Returns:
      the step value
    • setStep

      public void setStep(double step)
      Sets the step value of the slider.

      If the current value is not aligned with the new step, it's automatically adjusted to the nearest value that matches the step, which triggers a value change event. To set both the step and value explicitly, use the

      invalid reference
      setValue(value, min,
       max, step)
      method instead.
      Parameters:
      step - the step value
      Throws:
      IllegalArgumentException - if step is not positive
    • clear

      public void clear()
      Clears the slider value, setting it to the minimum value.
      See Also:
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • setValue

      public void setValue(Double value)
      Sets the value of the slider.
      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<TComponent extends com.vaadin.flow.component.slider.SliderBase<TComponent,TValue>,TValue>
      Overrides:
      setValue in class com.vaadin.flow.component.AbstractField<TComponent extends com.vaadin.flow.component.slider.SliderBase<TComponent,TValue>,TValue>
      Parameters:
      value - the value
      Throws:
      IllegalArgumentException - if value is not valid for the current min, max and step
    • setValue

      public void setValue(Double value, double min, double max)
      Sets the minimum, maximum, and value of the slider atomically.

      The step remains unchanged.

      Parameters:
      value - the value
      min - the minimum value
      max - the maximum value
      Throws:
      IllegalArgumentException - if min is greater than max
      IllegalArgumentException - if value is not valid for the given min, max and current step
    • setValue

      public void setValue(Double value, double min, double max, double step)
      Sets the minimum, maximum, step, and value of the slider atomically.
      Parameters:
      value - the value
      min - the minimum value
      max - the maximum value
      step - the step value
      Throws:
      IllegalArgumentException - if min is greater than max
      IllegalArgumentException - if step is not positive
      IllegalArgumentException - if value is not valid for the given min, max and step