diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2016-07-19 16:19:20 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-08-05 10:19:46 +0300 |
commit | 80e7941da9c74c893f8f55fe4b3c71bc36da44d1 (patch) | |
tree | 8dd8e8a1ec57e7e757ede1b63467fb49bc0f908c /documentation/components/components-slider.asciidoc | |
parent | 2d28180a4e90d11d085aa9aa5fa32c23ef375161 (diff) | |
download | vaadin-framework-80e7941da9c74c893f8f55fe4b3c71bc36da44d1.tar.gz vaadin-framework-80e7941da9c74c893f8f55fe4b3c71bc36da44d1.zip |
BoV: Components/Slider: API changes
Change-Id: I3a3056c86fae6629da8aeec6115b9650c954967c
Diffstat (limited to 'documentation/components/components-slider.asciidoc')
-rw-r--r-- | documentation/components/components-slider.asciidoc | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/documentation/components/components-slider.asciidoc b/documentation/components/components-slider.asciidoc index eb88433729..2311254570 100644 --- a/documentation/components/components-slider.asciidoc +++ b/documentation/components/components-slider.asciidoc @@ -28,7 +28,7 @@ and the _orientation_ of the slider. ---- // Create a vertical slider Slider vertslider = new Slider(1, 100); -vertslider.setOrientation(SliderOrientation.VERTICAL); +vertslider.setOrientation(Orientation.VERTICAL); ---- __min__:: Minimum value of the slider range. The default is 0.0. @@ -37,7 +37,7 @@ __max__:: Maximum value of the slider range. The default is 100.0. __resolution__:: The number of digits after the decimal point. The default is 0. -__orientation__:: The orientation can be either horizontal ([parameter]#SliderOrientation.HORIZONTAL#) or vertical ([parameter]#SliderOrientation.VERTICAL#). The default is horizontal. +__orientation__:: The orientation can be either horizontal ([parameter]#Orientation.HORIZONTAL#) or vertical ([parameter]#Orientation.VERTICAL#). The default is horizontal. As the [classname]#Slider# is a field component, you can handle value changes with a [classname]#ValueChangeListener#. The value of the [classname]#Slider# @@ -50,25 +50,16 @@ final Label vertvalue = new Label(); vertvalue.setSizeUndefined(); // Handle changes in slider value. -vertslider.addValueChangeListener( - new Property.ValueChangeListener() { - public void valueChange(ValueChangeEvent event) { - double value = (Double) vertslider.getValue(); - - // Use the value - box.setHeight((float) value, Sizeable.UNITS_PERCENTAGE); - vertvalue.setValue(String.valueOf(value)); - } +vertslider.addValueChangeListener(event -> { + float value = event.getValue().floatValue(); + box.setHeight(value, Unit.PERCENTAGE); + vertvalue.setValue(String.valueOf(value)); }); - -// The slider has to be immediate to send the changes -// immediately after the user drags the handle. -vertslider.setImmediate(true); ---- You can set the value with the [methodname]#setValue()# method defined in -[classname]#Slider# that takes the value as a native double value. The setter -can throw a [classname]#ValueOutOfBoundsException#, which you must handle. +[classname]#Slider# that takes the value as a [classname]#Double#. If the value +is outside the configured bounds, the setter throws a [classname]#ValueOutOfBoundsException#. [source, java] ---- @@ -81,9 +72,6 @@ try { } ---- -Alternatively, you can use the regular [methodname]#setValue(Object)#, which -does not do bounds checking. - <<figure.components.slider.example1>> shows both vertical (from the code examples) and horizontal sliders that control the size of a box. The slider values are displayed also in separate labels. |