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.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ---
  2. title: TextArea
  3. order: 10
  4. layout: page
  5. ---
  6. [[components.textarea]]
  7. = [classname]#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. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.textarea.basic[on-line example, window="_blank"].
  26. The result is shown in <<figure.components.textarea>>.
  27. [[figure.components.textarea]]
  28. .[classname]#TextArea# Example
  29. image::img/textarea-basic.png[width=40%, scaledwidth=50%]
  30. You can set the number of visible rows with [methodname]#setRows()# or use the
  31. regular [methodname]#setHeight()# to define the height in other units. If the
  32. actual number of rows exceeds the number, a vertical scrollbar will appear.
  33. Setting the height with [methodname]#setRows()# leaves space for a horizontal
  34. scrollbar, so the actual number of visible rows may be one higher if the
  35. scrollbar is not visible.
  36. You can set the width with the regular [methodname]#setWidth()# method. Setting
  37. the size with the __em__ unit, which is relative to the used font size, is
  38. recommended.
  39. [[components.textarea.wordwrap]]
  40. == Word Wrap
  41. The [methodname]#setWordwrap()# sets whether long lines are wrapped (
  42. [literal]#++true++# - default) when the line length reaches the width of the
  43. writing area. If the word wrap is disabled ( [literal]#++false++#), a vertical
  44. scrollbar will appear instead. The word wrap is only a visual feature and
  45. wrapping a long line does not insert line break characters in the field value;
  46. shortening a wrapped line will undo the wrapping.
  47. [source, java]
  48. ----
  49. TextArea area1 = new TextArea("Wrapping");
  50. area1.setWordwrap(true); // The default
  51. area1.setValue("A quick brown fox jumps over the lazy dog");
  52. TextArea area2 = new TextArea("Nonwrapping");
  53. area2.setWordwrap(false);
  54. area2.setValue("Victor jagt zw&ouml;lf Boxk&auml;mpfer quer "+
  55. "&uuml;ber den Sylter Deich");
  56. ----
  57. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.textarea.wordwrap[on-line example, window="_blank"].
  58. The result is shown in <<figure.components.textarea.wordwrap>>.
  59. [[figure.components.textarea.wordwrap]]
  60. .Word Wrap in [classname]#TextArea#
  61. image::img/textarea-wordwrap.png[width=60%, scaledwidth=100%]
  62. [[components.textarea.css]]
  63. == CSS Style Rules
  64. [source, css]
  65. ----
  66. .v-textarea { }
  67. ----
  68. The HTML structure of [classname]#TextArea# is extremely simple, consisting only
  69. of an element with [literal]#++v-textarea++# style.