my dog learned polymorphism
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
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: 24199

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

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Display message in a JTextField
It's not a secret anymore!