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 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ---
  2. title: CheckBox
  3. order: 15
  4. layout: page
  5. ---
  6. [[components.checkbox]]
  7. = [classname]#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]#OptionGroup# component in multiple
  17. selection mode, as described in
  18. <<dummy/../../../framework/components/components-optiongroup#components.optiongroup,"OptionGroup">>.
  19. Clicking on a check box will change its state. The state is a
  20. [classname]#Boolean# property that you can set with the [methodname]#setValue()#
  21. method and obtain with the [methodname]#getValue()# method of the
  22. [classname]#Property# interface. Changing the value of a check box will cause a
  23. [classname]#ValueChangeEvent#, which can be handled by a
  24. [classname]#ValueChangeListener#.
  25. [source, java]
  26. ----
  27. CheckBox checkbox1 = new CheckBox("Box with no Check");
  28. CheckBox checkbox2 = new CheckBox("Box with a Check");
  29. checkbox2.setValue(true);
  30. checkbox1.addValueChangeListener(event -> // Java 8
  31. checkbox2.setValue(! checkbox1.getValue()));
  32. checkbox2.addValueChangeListener(event -> // Java 8
  33. checkbox1.setValue(! checkbox2.getValue()));
  34. ----
  35. The result is shown in <<figure.components.checkbox.basic>>.
  36. [[figure.components.checkbox.basic]]
  37. .An Example of a Check Box
  38. image::img/checkbox-example1.png[width=35%, scaledwidth=50%]
  39. For an example on the use of check boxes in a table, see
  40. <<dummy/../../../framework/components/components-table#components.table,"Table">>.
  41. == CSS Style Rules
  42. [source, css]
  43. ----
  44. .v-checkbox { }
  45. .v-checkbox > input { }
  46. .v-checkbox > label { }
  47. ----
  48. The top-level element of a [classname]#CheckBox# has the
  49. [literal]#++v-checkbox++# style. It contains two sub-elements: the actual check
  50. box [literal]#++input++# element and the [literal]#++label++# element. If you
  51. want to have the label on the left, you can change the positions with "[literal]#++direction: rtl++#" for the top element.