You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

components-checkbox.asciidoc 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ---
  2. title: CheckBox
  3. order: 15
  4. layout: page
  5. ---
  6. [[components.checkbox]]
  7. = CheckBox
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/other/check-box"]
  11. endif::web[]
  12. [classname]#CheckBox# is a two-state selection component that can be either
  13. checked or unchecked. The caption of the check box will be placed right of the
  14. actual check box. Vaadin provides two ways to create check boxes: individual
  15. check boxes with the [classname]#CheckBox# component described in this section
  16. and check box groups with the [classname]#CheckBoxGroup# component, as described in
  17. <<dummy/../../../framework/components/components-optiongroups#components.optiongroups,"CheckBoxGroup and RadioButtonGroup">>.
  18. Clicking on a check box will change its state. The state is a [classname]#Boolean#
  19. property that you can set with the [methodname]#setValue()# method and obtain with
  20. the [methodname]#getValue()# method. Changing the value of a check box will cause
  21. a [classname]#ValueChangeEvent#, which can be handled by a [classname]#ValueChangeListener#.
  22. [source, java]
  23. ----
  24. CheckBox checkbox1 = new CheckBox("Box with no Check");
  25. CheckBox checkbox2 = new CheckBox("Box with a Check");
  26. checkbox2.setValue(true);
  27. checkbox1.addValueChangeListener(event ->
  28. checkbox2.setValue(! checkbox1.getValue()));
  29. ----
  30. The result is shown in <<figure.components.checkbox.basic>>.
  31. [[figure.components.checkbox.basic]]
  32. .An Example of a Check Box
  33. image::img/checkbox-example1.png[width=35%, scaledwidth=50%]
  34. == CSS Style Rules
  35. [source, css]
  36. ----
  37. .v-checkbox { }
  38. .v-checkbox > input { }
  39. .v-checkbox > label { }
  40. ----
  41. The top-level element of a [classname]#CheckBox# has the
  42. [literal]#++v-checkbox++# style. It contains two sub-elements: the actual check
  43. box [literal]#++input++# element and the [literal]#++label++# element.