While the TextInput component restricts the user to entering a single line of text, TextArea provides support for entering multiple lines of wrapped text. The following application demonstrates the use of TextArea:
Text areas are often placed in scroll panes because their content may grow too long to fit on the screen. However, as shown in the above example, they are not required to be direct descendants of a scroll pane - typing in the bottom text area causes the text area to grow as each new line is added. A top-level scroll pane that contains the entire application content displays a scroll bar as needed to accommodate the height of the bottom text area.
The BXML source for this example is shown below (there is no corresponding Java source):
<Window title="Text Areas" maximized="true" xmlns:bxml="http://pivot.apache.org/bxml" xmlns="org.apache.pivot.wtk"> <Border styles="{color:10}"> <ScrollPane horizontalScrollBarPolicy="fill"> <TablePane styles="{padding:8, verticalSpacing:8}"> <columns> <TablePane.Column width="1*"/> </columns> <TablePane.Row height="1*"> <Border styles="{color:10}"> <ScrollPane horizontalScrollBarPolicy="fill" verticalScrollBarPolicy="fill_to_capacity" preferredHeight="240"> <TextArea text="@sample1.txt"/> </ScrollPane> </Border> </TablePane.Row> <TablePane.Row height="-1"> <Border styles="{color:10}"> <TextArea minimumHeight="80" text="@sample2.txt"/> </Border> </TablePane.Row> </TablePane> </ScrollPane> </Border> </Window>
Though it is not demonstrated in this example, text areas may be flagged as non-editable by setting the "editable" flag to false. When non-editable, the user is still able to select text but is not allowed to modify it. This is useful when an application needs to present some read-only text to the user but still allow that text to be selected (e.g. for copy to the clipboard).
Next: Separators