Basic HTML version of Foils prepared 18 May 97

Foil 50 AWT Components -- Text Fields & Areas

From Java Tutorial - Spring 1997 Part 3:Graphics and the Abstract Windowing Toolkit Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


To add a text field for display or input one line of text (in this case, 30 characters wide):
  • TextField tf = new TextField("initial text", 30);
  • add(tf);
The text which is displayed can be changed:
  • tf.setText("now show a new text");
If the user can type input into the text field, it can be obtained:
  • stringvar = tf.getText();
Or you can disallow the user to type:
  • tf.setEditable(false);
The TextArea class also has these methods, but it can display multiple lines.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Thu Jan 8 1998