Cody
Cody

Reputation: 890

Java clear textfield after "Enter"

How can I clear the text in the input field after the user submits the message.

Im working on something similar to a chat. I've gotten to the point where when the user submits the message it gets sent but the message typed remains in the textbox, how can i make it automatically clear.

This is a part of my code, not sure if its enough.

private JTextField in;

public AESGUI() {

JLabel info = new JLabel("Message");
in = new JTextField(40);

Upvotes: 1

Views: 9720

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

Have a look at the JTextField API as well as its parent class, JTextComponent, where you'll find the method you need: setText(""). Just call it in the code that responds to "Enter", possibly an ActionListener that has been added to the JTextField.

If this information doesn't help you, then you'll have to give us more information. Note that your current posted code tells us very little about your problem and does not help us figure out where your problem is.

Upvotes: 6

Related Questions