• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stop text from wrapping

 
Tim Williams
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive me if this is a stupid question, but...
I want to use a JTextPane or JText area to show some text that I will load from a file.
However, I don't want the text to wrap. Instead I want a scrollbar (I don't care if it is shown all the time or not.)
Can anybody help?
Thanks,
Tim.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a JTextArea, all you have to do is call setLineWrap( false ) on it and stick it in a JScrollPane...

For a JTextPane, you have to override two methods... getScrollableTracksViewportWidth() and
setSize()...

Here's some code that shows how to turn off line wrap in both components...



-Nate
 
Tim Williams
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks , I will check this out this evening!
Tim.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!