The moose likes Swing / AWT / SWT / JFace and the fly likes Stop text from wrapping Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Stop text from wrapping" Watch "Stop text from wrapping" New topic
Author

Stop text from wrapping

Tim Williams
Greenhorn

Joined: Feb 12, 2001
Posts: 27
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

Joined: Oct 18, 2000
Posts: 4120

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Tim Williams
Greenhorn

Joined: Feb 12, 2001
Posts: 27
Thanks , I will check this out this evening!
Tim.
 
 
subject: Stop text from wrapping
 
Threads others viewed
Text editor in Java
i want to read from a textfield and compare it with an external file
textarea
Setting Policy entry
mailTo
developer file tools