Text Fields and Text Areas Text FieldsA text field is an input/output region on the
screen that holds one line of string data. A
text field is useful for entering or displaying such things as a persons name. Text fields are declared in much the same manner
as other window controls: TextField <name of field> =
<row>, <col>, The next table shows three commonly used text field methods:
Text fields usually open with no initial display of data. For example, the following code displays a label
and an empty text field for entering a person's name: Label nameLabel = addLabel ("Name",1,1,1,1); TextField nameField = addTextField ("",1,2,1,1); The method setEditable
can also be used with IntegerField
and DoubleField. This method is useful for making a field read
only. For example, nameField.setEditable (false); // Read-only field Text AreasA text area is similar to a text field, except that it can handle several lines of text at a time. A text area can be used for entering or displaying an address, table, schedule, or any multiline descriptive information. Text areas are declared as follows: TextArea <name of field> = <row>, <col>, <width>, <height>); Whereas a text field typically has a width and height of one, a text area is usually several columns wide and high. Here are some methods that manipulate text areas:
The following code would create a text area that allows the display of 5 rows of text: TextArea output = addTextArea ("", 1, 1, 2, 5); Text areas have scroll bars, similar to those used with text editors, to allow the user to view hidden parts of the output data. |
| ||||