How to create a Text Field in Java

A text field component is used for inputting or displaying a line of text information. To create a text field component, first declare the object to be of type JTextFiled. For example,

JTextField qtyfield;



Then invoke the javax.swing.JTextField constructor, for example

qtyfield = new JTextField (3);

where the constructor argument specifies the minimum number of columns in the text field itself. By default, a text field is editable; if a text field is to be used for outputting messages only, then use the javax.swing.text.JTextComponent method setEditable(false). Note that the JTextField class is a subclass of the JTextComponent class, as is the JTextArea class .Consequently, the setEditable method can also be used with text area components.

No comments:

Post a Comment