This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to handle ENTER key event in JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to handle ENTER key event in JTextArea" Watch "How to handle ENTER key event in JTextArea" New topic

How to handle ENTER key event in JTextArea


Joined: May 01, 2008
Posts: 14
I want to enter multiple lines in the text area by clicking enter key. I am not able to do that. When I press an enter key, the control is getting out it.

Please help me asap.

Thanks in advance.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
Welcome to the Ranch. Please confirm that you have got the correct displayed name.

Not sure about your problem, and might not be able to help myself, but I think you would have better chances of a useful reply if you post more details, including a little code showing what you have written (use the "code" button below and ctrl-C ctrl-V to copy it), and more of an explanation of exactly what you want your code to do.

And less of the "asap" thank you very much!
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

What is the class of the text area? Is it JTextArea, JEditorPane, JTextPane?

If it's JTextField, then you will need to change. It doesn't accept any line breaks. Instead, enter will trigger an ActionEvent.

How To Ask Questions How To Answer Questions
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
I just saw a good one on this in either the cattle drive or the faq's for jr
I agree. Here's the link:
subject: How to handle ENTER key event in JTextArea
It's not a secret anymore!