Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea

 
jamie ong
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
anyone know whether is it possible to detect a new line within a passage when copy and paste into the textarea box and how to do so.
many thanks!
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
maybe I don't understand you right, but a newline in Java is "\n" and on some OS also "\r". So in your case I would create a StringTokenizer.

This would print you out:
this is a test
over two lines
In this way you could detect every line until newline.
Bye
Rene
 
jamie ong
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm ok, so far i get what i want, how can i insert an extra word for every "\n" found?
thanks!
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok man, try this:

Please have a look to function replaceNewLine(). This function creates a new String by using every token. To every token you can add, what you want.
Hope this helps!
Rene
 
jamie ong
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thanks for your help! Rene
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic