• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JEditorPane disabling Line Wrap

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see that there's a way to setLineWrap with a JTextArea, but it seems that JEditorPane and JTextPane both automatically line wrap. I want to disable the line wrapping in the JEditorPane. Does anyone know how? I can't seem to fine the method for this.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since JEditorPane can use multiple document types(i.e. HTML, RTF, etc.) that can hold a variety of information( i.e. text, images, Components ), this would be hard to do... It may be possible to do this by extending the Document class to implement this behavior, but I would just suggest that if you need to control line-wrapping, stick with a JTextArea.

-Nate
 
Michael Szul
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JTextArea works fine, but I believe that if you use Styles, you have to use a JTextPane or JEditorPane. The text area is just a small part of my program, but it needs to be syntax aware, I don't think a JTextArea can accomplish this, can it?
I found something online that said to override the getScrollableViewportsWidth() method (I think that's the right one). It looked something like this:
class NewTextPane extends JEditorPane {
public NewTextPane() {
super();
}
public boolean getScrollableViewportsWidth() {
return false;
}
}
...but I couldn't get this thing to work. Am I on the right track?
 
Michael Szul
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If anyone is interested I found a fix for this problem in the book: Core Swing Advanced Programming by Kim Topley.
It uses the same technique above for overriding the default getScrollableViewportsWidth, but actually fixes a major bug that was causing this to originally fail.
I would post it, but I don't have the book handy right now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic