This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Display message in a JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Display message in a JTextField" Watch "Display message in a JTextField" New topic

Display message in a JTextField

Adam Henson

Joined: Dec 04, 2003
Posts: 1
How can I allocate a text string to a JTextField?
I need a message to be displayed in the field when a JButton on the pane is clicked.. What is the best way of doing this?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

In an ActionListener registered with the JButton, call setText("The String") on the JTextField.

[Jess in Action][AskingGoodQuestions]
It is sorta covered in the JavaRanch Style Guide.
subject: Display message in a JTextField