aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Word wrap and other issues with JTextPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Word wrap and other issues with JTextPane" Watch "Word wrap and other issues with JTextPane" New topic
Author

Word wrap and other issues with JTextPane

Poorav Chaudhari
Ranch Hand

Joined: Sep 17, 2002
Posts: 50
I am using NetBeans to develop my swing application. I have one JTextPane which I have placed within a JScrollPane. My first issue was to disable the line wrap. To do this I extended the JTextPane and overrode the getScrollableTracksViewportWidth() to return false. The problem I have is that once i created a wrapper for the JTextPane, when I run the application the width of the TextPane is 0 and when I start typing in the in the textpane it expands. I would like the size of the textpane to be the size of the scrollpane. Please tell me what I am missing. If i change the textpane definition to JTextPane() then the size of the textPane is the size of the scrollPane, but then obviously the line wrapping is enabled. So here is what I have

The textPane is defined as


And this is the code generated for the initialization of the textPane


I hope I am clear enough. Any idea what I can do to make sure the textPane is the same size of the scrollPane?


Poorav Chaudhari
gyan kumar
Ranch Hand

Joined: Sep 28, 2011
Posts: 61
try these urls
http://stackoverflow.com/questions/280106/jeditorpane-inside-jscrollpane-not-resizing-as-needed
http://www.java2s.com/Tutorial/Java/0240__Swing/LoadingaJTextPanewithContentusingStyleConstantstosetAlignFontsizeSpace.htm
http://www.java-forums.org/new-java/22187-how-use-jtextarea-jscrollpane.html
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
See: No Wrap Text Pane.
Poorav Chaudhari
Ranch Hand

Joined: Sep 17, 2002
Posts: 50
Thank you all for your input. What I ended up doing was to modify the getScrollableTracksViewportWidth() method as following.



I picked up this snippet from http://www.java2s.com/Code/Java/Swing-JFC/NonWrappingWrapTextPane.htm.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Word wrap and other issues with JTextPane