public class Slider extends Control
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:
import javafx.scene.control.Slider; 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:
import javafx.scene.control.Slider; Slider slider = new Slider(0, 1, 0.5); slider.setShowTickMarks(true); slider.setShowTickLabels(true); slider.setMajorTickUnit(0.25f); slider.setBlockIncrement(0.1f);
Type | Property and Description |
---|---|
DoubleProperty |
blockIncrement
The amount by which to adjust the slider if the track of the slider is
clicked.
|
<any> |
labelFormatter
A function for formatting the label for a major tick.
|
DoubleProperty |
majorTickUnit
The unit distance between major tick marks.
|
DoubleProperty |
max
The maximum value represented by this Slider.
|
IntegerProperty |
minorTickCount
The number of minor ticks to place between any two major ticks.
|
DoubleProperty |
min
The minimum value represented by this Slider.
|
<any> |
orientation
The orientation of the
Slider can either be horizontal
or vertical. |
BooleanProperty |
showTickLabels
Indicates that the labels for tick marks should be shown.
|
BooleanProperty |
showTickMarks
Specifies whether the
Skin implementation should show tick marks. |
BooleanProperty |
snapToTicks
Indicates whether the
value of the Slider should always
be aligned with the tick marks. |
BooleanProperty |
valueChanging
When true, indicates the current value of this Slider is changing.
|
DoubleProperty |
value
The current value represented by this Slider.
|
contextMenuProperty, skinClassNameProperty, skinProperty, tooltipProperty
Modifier and Type | Class and Description |
---|---|
private static class |
Slider.StyleableProperties |
Modifier and Type | Field and Description |
---|---|
private DoubleProperty |
blockIncrement
The amount by which to adjust the slider if the track of the slider is
clicked.
|
private static java.lang.String |
DEFAULT_STYLE_CLASS
*
Stylesheet Handling *
*
|
private static PseudoClass |
HORIZONTAL_PSEUDOCLASS_STATE |
private <any> |
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 <any> |
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 PseudoClass |
VERTICAL_PSEUDOCLASS_STATE |
Constructor and Description |
---|
Slider()
Creates a default Slider instance.
|
Slider(double min,
double max,
double value)
Constructs a Slider control with the specified slider min, max and current value values.
|
Modifier and Type | Method and Description |
---|---|
void |
adjustValue(double 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.
|
DoubleProperty |
blockIncrementProperty()
The amount by which to adjust the slider if the track of the slider is
clicked.
|
protected Skin<?> |
createDefaultSkin()
Create a new instance of the default skin for this control.
|
void |
decrement()
Decrements the value by
blockIncrement , bounded by max. |
void |
executeAccessibleAction(AccessibleAction action,
java.lang.Object... parameters) |
double |
getBlockIncrement()
Gets the value of the property blockIncrement.
|
static java.util.List<<any>> |
getClassCssMetaData() |
protected java.util.List<<any>> |
getControlCssMetaData() |
<any> |
getLabelFormatter()
Gets the value of the property labelFormatter.
|
double |
getMajorTickUnit()
Gets the value of the property majorTickUnit.
|
double |
getMax()
Gets the value of the property max.
|
double |
getMin()
Gets the value of the property min.
|
int |
getMinorTickCount()
Gets the value of the property minorTickCount.
|
Orientation |
getOrientation()
Gets the value of the property orientation.
|
double |
getValue()
Gets the value of the property value.
|
void |
increment()
Increments the value by
blockIncrement , bounded by max. |
private void |
initialize() |
boolean |
isShowTickLabels()
Gets the value of the property showTickLabels.
|
boolean |
isShowTickMarks()
Gets the value of the property showTickMarks.
|
boolean |
isSnapToTicks()
Gets the value of the property snapToTicks.
|
boolean |
isValueChanging()
Gets the value of the property valueChanging.
|
<any> |
labelFormatterProperty()
A function for formatting the label for a major tick.
|
DoubleProperty |
majorTickUnitProperty()
The unit distance between major tick marks.
|
DoubleProperty |
maxProperty()
The maximum value represented by this Slider.
|
IntegerProperty |
minorTickCountProperty()
The number of minor ticks to place between any two major ticks.
|
DoubleProperty |
minProperty()
The minimum value represented by this Slider.
|
<any> |
orientationProperty()
The orientation of the
Slider can either be horizontal
or vertical. |
java.lang.Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
java.lang.Object... parameters) |
void |
setBlockIncrement(double value)
Sets the value of the property blockIncrement.
|
void |
setLabelFormatter(<any> value)
Sets the value of the property labelFormatter.
|
void |
setMajorTickUnit(double value)
Sets the value of the property majorTickUnit.
|
void |
setMax(double value)
Sets the value of the property max.
|
void |
setMin(double value)
Sets the value of the property min.
|
void |
setMinorTickCount(int value)
Sets the value of the property minorTickCount.
|
void |
setOrientation(Orientation value)
Sets the value of the property orientation.
|
void |
setShowTickLabels(boolean value)
Sets the value of the property showTickLabels.
|
void |
setShowTickMarks(boolean value)
Sets the value of the property showTickMarks.
|
void |
setSnapToTicks(boolean value)
Sets the value of the property snapToTicks.
|
void |
setValue(double value)
Sets the value of the property value.
|
void |
setValueChanging(boolean value)
Sets the value of the property valueChanging.
|
BooleanProperty |
showTickLabelsProperty()
Indicates that the labels for tick marks should be shown.
|
BooleanProperty |
showTickMarksProperty()
Specifies whether the
Skin implementation should show tick marks. |
BooleanProperty |
snapToTicksProperty()
Indicates whether the
value of the Slider should always
be aligned with the tick marks. |
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.
|
BooleanProperty |
valueChangingProperty()
When true, indicates the current value of this Slider is changing.
|
DoubleProperty |
valueProperty()
The current value represented by this Slider.
|
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getControlChildren, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, loadSkinClass, setContextMenu, setSkin, setTooltip, skinClassNameProperty, skinProperty, tooltipProperty
public final DoubleProperty maxProperty
min
.getMax()
,
setMax(double)
public final DoubleProperty minProperty
max
.getMin()
,
setMin(double)
public final DoubleProperty valueProperty
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.getValue()
,
setValue(double)
public final BooleanProperty valueChangingProperty
isValueChanging()
,
setValueChanging(boolean)
public final <any> orientationProperty
Slider
can either be horizontal
or vertical.getOrientation()
,
setOrientation(Orientation)
public final BooleanProperty showTickLabelsProperty
Skin
implementation will only show labels if
showTickMarks
is also true.isShowTickLabels()
,
setShowTickLabels(boolean)
public final BooleanProperty showTickMarksProperty
Skin
implementation should show tick marks.isShowTickMarks()
,
setShowTickMarks(boolean)
public final DoubleProperty majorTickUnitProperty
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.
getMajorTickUnit()
,
setMajorTickUnit(double)
public final IntegerProperty minorTickCountProperty
getMinorTickCount()
,
setMinorTickCount(int)
public final BooleanProperty snapToTicksProperty
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.isSnapToTicks()
,
setSnapToTicks(boolean)
public final <any> labelFormatterProperty
Skin
implementation.getLabelFormatter()
,
#setLabelFormatter()
public final DoubleProperty blockIncrementProperty
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.getBlockIncrement()
,
setBlockIncrement(double)
private DoubleProperty max
min
.private DoubleProperty min
max
.private DoubleProperty value
private BooleanProperty valueChanging
private <any> orientation
Slider
can either be horizontal
or vertical.private BooleanProperty showTickLabels
Skin
implementation will only show labels if
showTickMarks
is also true.private BooleanProperty showTickMarks
Skin
implementation should show tick marks.private DoubleProperty majorTickUnit
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.
private IntegerProperty minorTickCount
private BooleanProperty snapToTicks
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.private <any> labelFormatter
Skin
implementation.private DoubleProperty blockIncrement
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.private static final java.lang.String DEFAULT_STYLE_CLASS
private static final PseudoClass VERTICAL_PSEUDOCLASS_STATE
private static final PseudoClass HORIZONTAL_PSEUDOCLASS_STATE
public Slider()
public Slider(double min, double max, double value)
min
- Slider minimum valuemax
- Slider maximum valuevalue
- Slider current valueprivate void initialize()
public final void setMax(double value)
public final double getMax()
public final DoubleProperty maxProperty()
min
.getMax()
,
setMax(double)
public final void setMin(double value)
public final double getMin()
public final DoubleProperty minProperty()
max
.getMin()
,
setMin(double)
public final void setValue(double value)
public final double getValue()
public final DoubleProperty valueProperty()
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.getValue()
,
setValue(double)
public final void setValueChanging(boolean value)
public final boolean isValueChanging()
public final BooleanProperty valueChangingProperty()
isValueChanging()
,
setValueChanging(boolean)
public final void setOrientation(Orientation value)
public final Orientation getOrientation()
public final <any> orientationProperty()
Slider
can either be horizontal
or vertical.getOrientation()
,
setOrientation(Orientation)
public final void setShowTickLabels(boolean value)
public final boolean isShowTickLabels()
public final BooleanProperty showTickLabelsProperty()
Skin
implementation will only show labels if
showTickMarks
is also true.isShowTickLabels()
,
setShowTickLabels(boolean)
public final void setShowTickMarks(boolean value)
public final boolean isShowTickMarks()
public final BooleanProperty showTickMarksProperty()
Skin
implementation should show tick marks.isShowTickMarks()
,
setShowTickMarks(boolean)
public final void setMajorTickUnit(double value)
public final double getMajorTickUnit()
public final DoubleProperty majorTickUnitProperty()
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.
getMajorTickUnit()
,
setMajorTickUnit(double)
public final void setMinorTickCount(int value)
public final int getMinorTickCount()
public final IntegerProperty minorTickCountProperty()
getMinorTickCount()
,
setMinorTickCount(int)
public final void setSnapToTicks(boolean value)
public final boolean isSnapToTicks()
public final BooleanProperty snapToTicksProperty()
value
of the Slider
should always
be aligned with the tick marks. This is honored even if the tick marks
are not shown.isSnapToTicks()
,
setSnapToTicks(boolean)
public final void setLabelFormatter(<any> value)
public final <any> getLabelFormatter()
public final <any> labelFormatterProperty()
Skin
implementation.getLabelFormatter()
,
#setLabelFormatter()
public final void setBlockIncrement(double value)
public final double getBlockIncrement()
public final DoubleProperty blockIncrementProperty()
snapToTicks
is true then the nearest tick mark to the adjusted
value will be used.getBlockIncrement()
,
setBlockIncrement(double)
public void adjustValue(double newValue)
value
to match newValue
. The
value
is 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.newValue
- the new adjusted valuepublic void increment()
blockIncrement
, bounded by max. If the
max is less than or equal to the min, then this method does nothing.public void decrement()
blockIncrement
, bounded by max. If the
max is less than or equal to the min, then this method does nothing.private void adjustValues()
private double snapValueToTicks(double val)
protected Skin<?> createDefaultSkin()
-fx-skin
or set explicitly in a sub-class with setSkin(...)
.createDefaultSkin
in class Control
public static java.util.List<<any>> getClassCssMetaData()
protected java.util.List<<any>> getControlCssMetaData()
getControlCssMetaData
in class Control
public java.lang.Object queryAccessibleAttribute(AccessibleAttribute attribute, java.lang.Object... parameters)
queryAccessibleAttribute
in class Control
public void executeAccessibleAction(AccessibleAction action, java.lang.Object... parameters)
executeAccessibleAction
in class Control