go to previous page   go to home page   go to next page


You may have forgotten to register a listener with the button. Without a listener, the events are ignored.

A Swing Component: JTextField

A JTextField is a box that contains a line of text. The user can type text into the box and the program can get it and then use it as data. The program can write the results of a calculation to a JTextField. Here is a label and a text field (both inside of an applet):

You must have Java enabled for your browser to see this applet.

To enter text into the field, first click the mouse pointer inside of it. This gives the field the keyboard focus (usually just called focus). When a component has focus, characters from the keyboard are directed to that component. A component gets focus by various means. The user might click it, or the program might give it focus.

Enter some text. Edit it using arrow keys, back space, and delete. But the field is not connected to any application code so nothing is done with the text.


(Review: ) Where is the class definition for JTextField?