TextArea

Live Demo

TextArea is a multi-line version of the TextField component described in “TextField”.

The following example creates a simple text area:

Java

  1. // Create the area
  2. TextArea area = new TextArea("Big Area");
  3. // Put some content in it
  4. area.setValue("A row\n"+
  5. "Another row\n"+
  6. "Yet another row");

The result is shown in TextArea Example.

textarea basic

TextArea Example

You can set the number of visible rows with setRows() or use the regular setHeight() to define the height in other units. If the actual number of rows exceeds the number, a vertical scrollbar will appear. Setting the height with setRows() leaves space for a horizontal scrollbar, so the actual number of visible rows may be one higher if the scrollbar is not visible.

You can set the width with the regular setWidth() method. Setting the size with the em unit, which is relative to the used font size, is recommended.

Word Wrap

The setWordwrap() sets whether long lines are wrapped ( true - default) when the line length reaches the width of the writing area. If the word wrap is disabled ( false), a vertical scrollbar will appear instead. The word wrap is only a visual feature and wrapping a long line does not insert line break characters in the field value; shortening a wrapped line will undo the wrapping.

Java

  1. TextArea area1 = new TextArea("Wrapping");
  2. area1.setWordWrap(true); // The default
  3. area1.setValue("A quick brown fox jumps over the lazy dog");
  4. TextArea area2 = new TextArea("Nonwrapping");
  5. area2.setWordWrap(false);
  6. area2.setValue("Victor jagt zwölf Boxkämpfer quer "+
  7. "über den Sylter Deich");

The result is shown in Word Wrap in TextArea.

textarea wordwrap

Word Wrap in TextArea

CSS Style Rules

CSS

  1. .v-textarea { }

The HTML structure of TextArea is extremely simple, consisting only of an element with v-textarea style.