• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextArea testing for VK_ENTER, to send it. But can't get rid of the peskie Enter key  RSS feed

 
joe vasher
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a JTextArea for input, I am able to detect the enter key (VK_ENTER) and then send the text off then I set the text area back to "". This has a very tough to figure out problem. I can't seem to remove the enter key from the text String.. I have tried replace("\n","") and "\\n" and even an article suggested "\\\\n" which seems to not find or replace it.

Any suggestions?

thanks (just in case the above is confusing including the code snippet.)

 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a KeyListener.

Swing was designed to be used with Key Bindings (click the link if you don't know what this is). The default Action for the Enter key will insert a newline string into the Document.

You need to replace this Action with one of your own.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!