Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JEditorPane disabling Line Wrap  RSS feed

 
Michael Szul
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!