13.19. The TextField Class

Textfields create boxed areas to display or read a single line of text. See TextArea (Section 13.20) for a component that can display multiple lines. Java textfields do not permit mixed fonts or colors within a single textfield. If a textfield is being used for input, you typically allocate it (perhaps with a default entry or size) by specifying everything in the constructor, as follows:

TextField lastNameField = new TextField(15);
TextField langField = new TextField("Java");

Textfields used only for display are similar but require a call to setEditable to turn off input capability. Also, the value is often filled in through a separate step, since it might not be available when ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.