JTextField
|
JTextField x = new JTextField();
or:
JTextField x = new JTextField( #columns );
|
JTextFieldObjVar.setEditable( false );
|
To make a TextField editable (suitable for input ):
JTextFieldObjVar.setEditable( true );
|
JTextFieldObjVar.setText("ABC");
|
To read the string stored in the text field :
String s = JTextFieldObjVar.getText( );
|
import java.awt.*;
import javax.swing.*;
public class TextField
{
public static void main(String[] args)
{
JFrame f = new JFrame("My GUI");
JTextField x;
x = new JTextField(); // Make a JTextField
f.getContentPane().add(x); // Stick
x.setEditable(false); // Output only
x.setText("Hello World");
f.setSize(400, 300);
f.setVisible(true);
}
}
|