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