• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question on JTextArea  RSS feed

 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I'm new to Swing and in one of my first little apps
I have a JTextArea in a JScrollPane!
What I want to ask is that how can I make so that
each new insert into the textarea begins with a new line,
as if you've pressed Enter and typed a new line!
Regards, Fedai!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you inserting text to the JTextArea? By typing or programmatically through calling JTextArea.append()?

If you are doing it through append(), you just need to add a "\n" (newline character) to the end of the strings you are appending.

If it is through typing, you need to add a FocusListener to the JTextArea, so that each time the user re-enters the JTextArea, a "\n" is appended to the JTextArea.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!