The java javax.swing package provides a JTextField component that allows users to input text data. The setEnabled() method is a part of this component which sets whether the text field can be edited or not. The default value of this property is true, i.e., the text field is editable by default.
Example:
JTextField textField = new JTextField("Enter text here"); textField.setEnabled(false);
This example creates a JTextField object and disables it, making it read-only.
Another example:
JTextField textField = new JTextField("Enter text here"); JButton button = new JButton("Enable"); JButton button2 = new JButton("Disable");
This example creates a JTextField object and two buttons that enable and disable the text field as per user preference by invoking the setEnabled() method accordingly.
The package library used in these examples is java.swing package.
Java JTextField.setEnabled - 30 examples found. These are the top rated real world Java examples of javax.swing.JTextField.setEnabled extracted from open source projects. You can rate examples to help us improve the quality of examples.