This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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.)

 
Rancher
Posts: 2940
19
  • 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!