APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javafx.scene.control

public Class Slider

extends Control
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List, javafx.beans.property.BooleanProperty, .DoubleProperty, .DoublePropertyBase, .IntegerProperty, .ObjectProperty, .SimpleBooleanProperty, .SimpleObjectProperty, javafx.beans.value.WritableValue, javafx.geometry.Orientation, javafx.scene.AccessibleAction, .AccessibleAttribute, .AccessibleRole, javafx.util.StringConverter, com.sun.javafx.util.Utils, javafx.css.CssMetaData, .PseudoClass, .StyleableBooleanProperty, .StyleableDoubleProperty, .StyleableIntegerProperty, .StyleableObjectProperty, .Styleable, .StyleableProperty, javafx.css.converter.BooleanConverter, .EnumConverter, .SizeConverter, javafx.scene.control.skin.SliderSkin

The Slider Control is used to display a continuous or discrete range of valid numeric choices and allows the user to interact with the control. It is typically represented visually as having a "track" and a "knob" or "thumb" which is dragged within the track. The Slider can optionally show tick marks and labels indicating the different slider position values.

The three fundamental variables of the slider are min, max, and value. The value should always be a number within the range defined by min and max. min should always be less than or equal to max (although a slider whose min and max are equal is a degenerate case that makes no sense). min defaults to 0, whereas max defaults to 100.

This first example creates a slider whose range, or span, goes from 0 to 1, and whose value defaults to .5:

 Slider slider = new Slider(0, 1, 0.5);

This next example shows a slider with customized tick marks and tick mark labels, which also spans from 0 to 1:

 Slider slider = new Slider(0, 1, 0.5);
slider.setShowTickMarks(true);
slider.setShowTickLabels(true);
slider.setMajorTickUnit(0.25f);
slider.setBlockIncrement(0.1f);
Image of the Slider control
Since
JavaFX 2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private DoubleProperty
blockIncrement

The amount by which to adjust the slider if the track of the slider is clicked.

private static final String
private static final PseudoClass
private ObjectProperty<StringConverter<Double>>
labelFormatter

A function for formatting the label for a major tick.

private DoubleProperty
majorTickUnit

The unit distance between major tick marks.

private DoubleProperty
max

The maximum value represented by this Slider.

private DoubleProperty
min

The minimum value represented by this Slider.

private IntegerProperty
minorTickCount

The number of minor ticks to place between any two major ticks.

private ObjectProperty<Orientation>
orientation

The orientation of the Slider can either be horizontal or vertical.

private BooleanProperty
showTickLabels

Indicates that the labels for tick marks should be shown.

private BooleanProperty
showTickMarks

Specifies whether the Skin implementation should show tick marks.

private BooleanProperty
snapToTicks

Indicates whether the value of the Slider should always be aligned with the tick marks.

private DoubleProperty
value

The current value represented by this Slider.

private BooleanProperty
valueChanging

When true, indicates the current value of this Slider is changing.

private static final PseudoClass

Constructor Summary

AccessConstructor and Description
public
Slider()

Creates a default Slider instance.

public
Slider(double
Slider minimum value
min
,
double
Slider maximum value
max
,
double
Slider current value
value
)

Constructs a Slider control with the specified slider min, max and current value values.

Method Summary

Modifier and TypeMethod and Description
public void
adjustValue(double
the new adjusted value
newValue
)

Adjusts value to match newValue.

private void
adjustValues()

Ensures that min is always < max, that value is always somewhere between the two, and that if snapToTicks is set then the value will always be set to align with a tick mark.

public final DoubleProperty
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public void
decrement()

Decrements the value by blockIncrement, bounded by max.

public void
executeAccessibleAction(AccessibleAction action, Object... parameters)

Overrides javafx.scene.control.Control.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

public final double
public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

protected List<CssMetaData<? extends Styleable, ?>>
getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

public final StringConverter<Double>
public final double
public final double
public final double
public final int
public final Orientation
public final double
public void
increment()

Increments the value by blockIncrement, bounded by max.

private void
public final boolean
public final boolean
public final boolean
public final boolean
public final ObjectProperty<StringConverter<Double>>
public final DoubleProperty
public final DoubleProperty
public final IntegerProperty
public final DoubleProperty
public final ObjectProperty<Orientation>
public Object
queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.Control.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

public final void
setBlockIncrement(double value)

public final void
public final void
setMajorTickUnit(double value)

public final void
setMax(double value)

public final void
setMin(double value)

public final void
setMinorTickCount(int value)

public final void
public final void
setShowTickLabels(boolean value)

public final void
setShowTickMarks(boolean value)

public final void
setSnapToTicks(boolean value)

public final void
setValue(double value)

public final void
setValueChanging(boolean value)

public final BooleanProperty
public final BooleanProperty
public final BooleanProperty
private double
snapValueToTicks(double val)

Utility function which, given the specified value, will position it either aligned with a tick, or simply clamp between min & max value, depending on whether snapToTicks is set.

public final BooleanProperty
public final DoubleProperty
Inherited from javafx.scene.control.Control:
computeMaxHeightcomputeMaxWidthcomputeMinHeightcomputeMinWidthcomputePrefHeightcomputePrefWidthcontextMenuPropertygetBaselineOffsetgetContextMenugetControlChildrengetCssMetaDatagetInitialFocusTraversablegetSkingetTooltipisResizablelayoutChildrenloadSkinClasssetContextMenusetSkinsetTooltipskinClassNamePropertyskinPropertytooltipProperty

Field Detail

blockIncrementback to summary
private DoubleProperty blockIncrement

The amount by which to adjust the slider if the track of the slider is clicked. This is used when manipulating the slider position using keys. If snapToTicks is true then the nearest tick mark to the adjusted value will be used.

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS
HORIZONTAL_PSEUDOCLASS_STATEback to summary
private static final PseudoClass HORIZONTAL_PSEUDOCLASS_STATE
labelFormatterback to summary
private ObjectProperty<StringConverter<Double>> labelFormatter

A function for formatting the label for a major tick. The number representing the major tick will be passed to the function. If this function is not specified, then a default function will be used by the Skin implementation.

majorTickUnitback to summary
private DoubleProperty majorTickUnit

The unit distance between major tick marks. For example, if the min is 0 and the max is 100 and the majorTickUnit is 25, then there would be 5 tick marks: one at position 0, one at position 25, one at position 50, one at position 75, and a final one at position 100.

This value should be positive and should be a value less than the span. Out of range values are essentially the same as disabling tick marks.

maxback to summary
private DoubleProperty max

The maximum value represented by this Slider. This must be a value greater than min.

minback to summary
private DoubleProperty min

The minimum value represented by this Slider. This must be a value less than max.

minorTickCountback to summary
private IntegerProperty minorTickCount

The number of minor ticks to place between any two major ticks. This number should be positive or zero. Out of range values will disable disable minor ticks, as will a value of zero.

orientationback to summary
private ObjectProperty<Orientation> orientation

The orientation of the Slider can either be horizontal or vertical.

showTickLabelsback to summary
private BooleanProperty showTickLabels

Indicates that the labels for tick marks should be shown. Typically a Skin implementation will only show labels if showTickMarks is also true.

showTickMarksback to summary
private BooleanProperty showTickMarks

Specifies whether the Skin implementation should show tick marks.

snapToTicksback to summary
private BooleanProperty snapToTicks

Indicates whether the value of the Slider should always be aligned with the tick marks. This is honored even if the tick marks are not shown.

valueback to summary
private DoubleProperty value

The current value represented by this Slider. This value must always be between min and max, inclusive. If it is ever out of bounds either due to min or max changing or due to itself being changed, then it will be clamped to always remain valid.

valueChangingback to summary
private BooleanProperty valueChanging

When true, indicates the current value of this Slider is changing. It provides notification that the value is changing. Once the value is computed, it is reset back to false.

VERTICAL_PSEUDOCLASS_STATEback to summary
private static final PseudoClass VERTICAL_PSEUDOCLASS_STATE

Constructor Detail

Sliderback to summary
public Slider()

Creates a default Slider instance.

Sliderback to summary
public Slider(double min, double max, double value)

Constructs a Slider control with the specified slider min, max and current value values.

Parameters
min:double

Slider minimum value

max:double

Slider maximum value

value:double

Slider current value

Method Detail

adjustValueback to summary
public void adjustValue(double newValue)

Adjusts value to match newValue. The valueis the actual amount between the min and max. This function also takes into account snapToTicks, which is the main difference between adjustValue and setValue. It also ensures that the value is some valid number between min and max.

Note

This function is intended to be used by experts, primarily by those implementing new Skins or Behaviors. It is not common for developers or designers to access this function directly.

Parameters
newValue:double

the new adjusted value

adjustValuesback to summary
private void adjustValues()

Ensures that min is always < max, that value is always somewhere between the two, and that if snapToTicks is set then the value will always be set to align with a tick mark.

blockIncrementPropertyback to summary
public final DoubleProperty blockIncrementProperty()
createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
decrementback to summary
public void decrement()

Decrements the value by blockIncrement, bounded by max. If the max is less than or equal to the min, then this method does nothing.

executeAccessibleActionback to summary
public void executeAccessibleAction(AccessibleAction action, Object... parameters)

Overrides javafx.scene.control.Control.executeAccessibleAction.

Doc from javafx.scene.control.Control.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

This method is commonly overridden by subclasses to implement action that are required for a specific role.
If a particular action is not handled, the superclass implementation must be called.

Annotations
@Override
getBlockIncrementback to summary
public final double getBlockIncrement()
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getControlCssMetaDataback to summary
protected List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Doc from javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

Annotations
@Override
Since
JavaFX 8.0
getLabelFormatterback to summary
public final StringConverter<Double> getLabelFormatter()
getMajorTickUnitback to summary
public final double getMajorTickUnit()
getMaxback to summary
public final double getMax()
getMinback to summary
public final double getMin()
getMinorTickCountback to summary
public final int getMinorTickCount()
getOrientationback to summary
public final Orientation getOrientation()
getValueback to summary
public final double getValue()
incrementback to summary
public void increment()

Increments the value by blockIncrement, bounded by max. If the max is less than or equal to the min, then this method does nothing.

initializeback to summary
private void initialize()
isShowTickLabelsback to summary
public final boolean isShowTickLabels()
isShowTickMarksback to summary
public final boolean isShowTickMarks()
isSnapToTicksback to summary
public final boolean isSnapToTicks()
isValueChangingback to summary
public final boolean isValueChanging()
labelFormatterPropertyback to summary
public final ObjectProperty<StringConverter<Double>> labelFormatterProperty()
majorTickUnitPropertyback to summary
public final DoubleProperty majorTickUnitProperty()
maxPropertyback to summary
public final DoubleProperty maxProperty()
minorTickCountPropertyback to summary
public final IntegerProperty minorTickCountProperty()
minPropertyback to summary
public final DoubleProperty minProperty()
orientationPropertyback to summary
public final ObjectProperty<Orientation> orientationProperty()
queryAccessibleAttributeback to summary
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.Control.queryAccessibleAttribute.

Doc from javafx.scene.control.Control.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
If a particular attribute is not handled, the superclass implementation must be called.

Annotations
@Override
setBlockIncrementback to summary
public final void setBlockIncrement(double value)
setLabelFormatterback to summary
public final void setLabelFormatter(StringConverter<Double> value)
setMajorTickUnitback to summary
public final void setMajorTickUnit(double value)
setMaxback to summary
public final void setMax(double value)
setMinback to summary
public final void setMin(double value)
setMinorTickCountback to summary
public final void setMinorTickCount(int value)
setOrientationback to summary
public final void setOrientation(Orientation value)
setShowTickLabelsback to summary
public final void setShowTickLabels(boolean value)
setShowTickMarksback to summary
public final void setShowTickMarks(boolean value)
setSnapToTicksback to summary
public final void setSnapToTicks(boolean value)
setValueback to summary
public final void setValue(double value)
setValueChangingback to summary
public final void setValueChanging(boolean value)
showTickLabelsPropertyback to summary
public final BooleanProperty showTickLabelsProperty()
showTickMarksPropertyback to summary
public final BooleanProperty showTickMarksProperty()
snapToTicksPropertyback to summary
public final BooleanProperty snapToTicksProperty()
snapValueToTicksback to summary
private double snapValueToTicks(double val)

Utility function which, given the specified value, will position it either aligned with a tick, or simply clamp between min & max value, depending on whether snapToTicks is set.

Note

This function is intended to be used by experts, primarily by those implementing new Skins or Behaviors. It is not common for developers or designers to access this function directly.

valueChangingPropertyback to summary
public final BooleanProperty valueChangingProperty()
valuePropertyback to summary
public final DoubleProperty valueProperty()
javafx.scene.control back to summary

private Class Slider.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<Slider, Number>
private static final CssMetaData<Slider, Number>
private static final CssMetaData<Slider, Number>
private static final CssMetaData<Slider, Orientation>
private static final CssMetaData<Slider, Boolean>
private static final CssMetaData<Slider, Boolean>
private static final CssMetaData<Slider, Boolean>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BLOCK_INCREMENTback to summary
private static final CssMetaData<Slider, Number> BLOCK_INCREMENT
MAJOR_TICK_UNITback to summary
private static final CssMetaData<Slider, Number> MAJOR_TICK_UNIT
MINOR_TICK_COUNTback to summary
private static final CssMetaData<Slider, Number> MINOR_TICK_COUNT
ORIENTATIONback to summary
private static final CssMetaData<Slider, Orientation> ORIENTATION
SHOW_TICK_LABELSback to summary
private static final CssMetaData<Slider, Boolean> SHOW_TICK_LABELS
SHOW_TICK_MARKSback to summary
private static final CssMetaData<Slider, Boolean> SHOW_TICK_MARKS
SNAP_TO_TICKSback to summary
private static final CssMetaData<Slider, Boolean> SNAP_TO_TICKS
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()