• 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:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Stop text from wrapping

 
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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!