• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to stop text continuing horizontally in a textarea?

 
Alan Smith
Ranch Hand
Posts: 185
Firefox Browser Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have an editable textarea for writing text into complete with a scrollpane. The scrollpane constructor is 'sp = new JScrollPane(ta,sp.VERTICAL_SCROLLBAR_AS_NEEDED,sp.HORIZONTAL_SCROLLBAR_NEVER);' where ta is the textarea. The problem is that the text doesn't jump to the next line below when I reach the edge of the text area. Any help? I thought disabling the horizontal scrollpane would do it but it just disappears into the void!

Cheers
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextArea#setLineWrap(true)
JTextArea#setWrapStyleWord(true)
 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrapping of text is controlled by the JTextAea. There are two methods of interest. One to turn "wrapping" on. The otther to control whether wrapping is done at the word or character level.

Also, there is no need to play with the scrollpane scrolling properties. Just create the scrollPane with the JTextArea as the only parameter.
 
Alan Smith
Ranch Hand
Posts: 185
Firefox Browser Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!