Make JTextField not editable in Java
Description
The following code shows how to make JTextField not editable.
Example
/* w w w .j a va 2 s. c o m*/
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Main {
public static void main(String[] args) {
JFrame f = new JFrame("Editability Example");
String firstFieldText = "An editable text field";
JTextField firstField = new JTextField(firstFieldText, 20);
f.setLayout(new FlowLayout());
f.getContentPane().add(firstField);
firstField.setEditable(false);
f.pack();
f.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »