Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2005

Tip: Looking for answers? Try searching our database.

JEditorPane Text Wrapping Question

Thread view: 
Vincent - 16 Feb 2005 14:43 GMT
I am trying to implement a text editor in Java, but dont want the
jeditorpane to text wrap by default, however i need to use a jeditorpane or
textpane in order to do text highlighting, is there anyway i can turn off
text wrapping all together i.e so people can write an entire essay on one
line if they want? and scroll horizontally?
Thanks
Vincent - 16 Feb 2005 15:21 GMT
Thanks anyway ive figured it out, if i simply add my textcomponent to jpanel
and then add the jpanel to the scroll pane the wrapping problem is overcome
thanks
Vince

>I am trying to implement a text editor in Java, but dont want the
>jeditorpane to text wrap by default, however i need to use a jeditorpane or
>textpane in order to do text highlighting, is there anyway i can turn off
>text wrapping all together i.e so people can write an entire essay on one
>line if they want? and scroll horizontally?
> Thanks
John McGrath - 16 Feb 2005 16:22 GMT
> if i simply add my textcomponent to jpanel and then add the jpanel to
> the scroll pane the wrapping problem is overcome

That will work, although there is another way that is a little simpler and
more flexible.

A JTextPane will *always* wrap text at its width, and it requests a width
equal to the width of its longest paragraph.  By placing it in a JPanel
using a FlowLayout or similar layout manager, you cause it to be sized to
that preferred width, which will prevent wrapping from occurring.

Since JTextPane implements the Scrollable interface, you can tell the
enclosing JScrollPane to size the JTextArea at its preferred width, as
opposed to the width of the viewport, by returning false from the
getScrollableTracksViewportWidth() method.

  JTextPane pane = new JTextPane() {
     public boolean getScrollableTracksViewportWidth() {
        return false;
     }
  };

Signature

Regards,

John McGrath



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.