--- title: Slider order: 28 layout: page --- [[components.slider]] = [classname]#Slider# ifdef::web[] [.sampler] image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/other/slider"] endif::web[] The [classname]#Slider# is a vertical or horizontal bar that allows setting a numeric value within a defined range by dragging a bar handle with the mouse. The value is shown when dragging the handle. [[figure.components.slider.example1]] .Vertical and horizontal [classname]#Slider# components image::img/slider-example1-hi.png[width=40%, scaledwidth=70%] [classname]#Slider# has a number of different constructors that take a combination of the caption, _minimum_ and _maximum_ value, _resolution_, and the _orientation_ of the slider. [source, java] ---- // Create a vertical slider Slider vertslider = new Slider(1, 100); vertslider.setOrientation(Orientation.VERTICAL); ---- __min__:: Minimum value of the slider range. The default is 0.0. __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]#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# field is a [classname]#Double# object. [source, java] ---- // Shows the value of the vertical slider final Label vertvalue = new Label(); vertvalue.setSizeUndefined(); // Handle changes in slider value. vertslider.addValueChangeListener(event -> { float value = event.getValue().floatValue(); box.setHeight(value, Unit.PERCENTAGE); vertvalue.setValue(String.valueOf(value)); }); ---- You can set the value with the [methodname]#setValue()# method defined in [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] ---- // Set the initial value. This has to be set after the // listener is added if we want the listener to handle // also this value change. try { vertslider.setValue(50.0); } catch (ValueOutOfBoundsException e) { } ---- <> 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. == CSS Style Rules [source, css] ---- .v-slider {} .v-slider-base {} .v-slider-handle {} ---- The enclosing style for the [classname]#Slider# is [literal]#++v-slider++#. The slider bar has style [literal]#++v-slider-base++#. Even though the handle is higher (for horizontal slider) or wider (for vertical slider) than the bar, the handle element is nevertheless contained within the slider bar element. The appearance of the handle comes from a background image defined in the __background__ CSS property. Vaadin 6, 7, 8 is a Java framework for modern Java web applications: https://github.com/vaadin/frameworkwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/components/components-checkbox.asciidoc
blob: 4e1205be8f71fd4a97672090b025e9fdb37fb90c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: CheckBox
order: 15
layout: page
---

[[components.checkbox]]
= CheckBox

ifdef::web[]
[.sampler]
image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/other/check-box"]
endif::web[]

[classname]#CheckBox# is a two-state selection component that can be either
checked or unchecked. The caption of the check box will be placed right of the
actual check box. Vaadin provides two ways to create check boxes: individual
check boxes with the [classname]#CheckBox# component described in this section
and check box groups with the [classname]#CheckBoxGroup# component, as described in
<<dummy/../../../framework/components/components-optiongroups#components.optiongroups,"CheckBoxGroup and RadioButtonGroup">>.

Clicking on a check box will change its state. The state is a [classname]#Boolean#
property that you can set with the [methodname]#setValue()# method and obtain with
the [methodname]#getValue()# method. Changing the value of a check box will cause
a [classname]#ValueChangeEvent#, which can be handled by a [classname]#ValueChangeListener#.


[source, java]
----
CheckBox checkbox1 = new CheckBox("Box with no Check");
CheckBox checkbox2 = new CheckBox("Box with a Check");

checkbox2.setValue(true);

checkbox1.addValueChangeListener(event ->
    checkbox2.setValue(! checkbox1.getValue()));
----

The result is shown in <<figure.components.checkbox.basic>>.

[[figure.components.checkbox.basic]]
.An Example of a Check Box
image::img/checkbox-example1.png[width=35%, scaledwidth=50%]


== CSS Style Rules


[source, css]
----
.v-checkbox { }
  .v-checkbox > input { }
  .v-checkbox > label { }
----

The top-level element of a [classname]#CheckBox# has the
[literal]#++v-checkbox++# style. It contains two sub-elements: the actual check
box [literal]#++input++# element and the [literal]#++label++# element. If you
want to have the label on the left, you can change the positions with "[literal]#++direction: rtl++#" for the top element.