Java-Swing:Introduction to Swing - Introduction to JTextField

From Juneday education
Jump to: navigation, search


Screenshot of the JTextField example

A JTextField is a component for allowing the user to input one line of text. The JTextField can have an action listener, which reacts to the user's pressing the Enter key. The three main methods of a JTextField are quite self-explanatory:

  • void addActionListener(ActionListener al)
  • String getText()
  • void setText(String text)

Some other useful methods include:

  • requestFocus()
  • selectAll()

Teaching materials



Further reading

Where to go next

« PreviousBook TOCNext »