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-textarea.asciidoc 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ---
  2. title: TextArea
  3. order: 10
  4. layout: page
  5. ---
  6. [[components.textarea]]
  7. = TextArea
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/text-input/text-area"]
  11. endif::web[]
  12. [classname]#TextArea# is a multi-line version of the [classname]#TextField#
  13. component described in
  14. <<dummy/../../../framework/components/components-textfield#components.textfield,"TextField">>.
  15. The following example creates a simple text area:
  16. [source, java]
  17. ----
  18. // Create the area
  19. TextArea area = new TextArea("Big Area");
  20. // Put some content in it
  21. area.setValue("A row\n"+
  22. "Another row\n"+
  23. "Yet another row");
  24. ----
  25. The result is shown in <<figure.components.textarea>>.
  26. [[figure.components.textarea]]
  27. .[classname]#TextArea# Example
  28. image::img/textarea-basic.png[width=40%, scaledwidth=50%]
  29. You can set the number of visible rows with [methodname]#setRows()# or use the
  30. regular [methodname]#setHeight()# to define the height in other units. If the
  31. actual number of rows exceeds the number, a vertical scrollbar will appear.
  32. Setting the height with [methodname]#setRows()# leaves space for a horizontal
  33. scrollbar, so the actual number of visible rows may be one higher if the
  34. scrollbar is not visible.
  35. You can set the width with the regular [methodname]#setWidth()# method. Setting
  36. the size with the __em__ unit, which is relative to the used font size, is
  37. recommended.
  38. [[components.textarea.wordwrap]]
  39. == Word Wrap
  40. The [methodname]#setWordwrap()# sets whether long lines are wrapped (
  41. [literal]#++true++# - default) when the line length reaches the width of the
  42. writing area. If the word wrap is disabled ( [literal]#++false++#), a vertical
  43. scrollbar will appear instead. The word wrap is only a visual feature and
  44. wrapping a long line does not insert line break characters in the field value;
  45. shortening a wrapped line will undo the wrapping.
  46. [source, java]
  47. ----
  48. TextArea area1 = new TextArea("Wrapping");
  49. area1.setWordWrap(true); // The default
  50. area1.setValue("A quick brown fox jumps over the lazy dog");
  51. TextArea area2 = new TextArea("Nonwrapping");
  52. area2.setWordWrap(false);
  53. area2.setValue("Victor jagt zw&ouml;lf Boxk&auml;mpfer quer "+
  54. "&uuml;ber den Sylter Deich");
  55. ----
  56. The result is shown in <<figure.components.textarea.wordwrap>>.
  57. [[figure.components.textarea.wordwrap]]
  58. .Word Wrap in [classname]#TextArea#
  59. image::img/textarea-wordwrap.png[width=60%, scaledwidth=100%]
  60. [[components.textarea.css]]
  61. == CSS Style Rules
  62. [source, css]
  63. ----
  64. .v-textarea { }
  65. ----
  66. The HTML structure of [classname]#TextArea# is extremely simple, consisting only
  67. of an element with [literal]#++v-textarea++# style.