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
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

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
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
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.

I agree. Here's the link: http://aspose.com/file-tools
subject: Word wrap and other issues with JTextPane
Similar Threads
JTable Problem
problem: JTextPane doesn't wrap
Adding an Image to a JTextPane
Cant show an object which extends JPanel in the form?
Matisse designer_problem with displaying drawn circle at JPanel/also animation problem