aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Make JTextPane adjust height to content Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Make JTextPane adjust height to content" Watch "Make JTextPane adjust height to content" New topic
Author

Make JTextPane adjust height to content

Milutin Markovic
Greenhorn

Joined: Mar 18, 2010
Posts: 12
I have applet in witch is JTextPane, from database reads StyledDocuments.
I'm trying to get a JTextPane to adjust its height according to whatever content I feed it. All I can do is to set a fixed height in pixels using Dimension.

How do I make the JTextPane collapse/expand so it will fit to contents?

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2176
    
    7
Users don't like the size of components to keep changing size. Normally you add the text pane to a JScrollPane and set the preferred size of the scroll pane to be a reasonable size. Then srollbar will appear if necessary. This is the way all applications are designed like you web browser or even this forum. Scroll bars will appear if the text of you question is too long.
Stanislav Lapitsky
Ranch Hand

Joined: Dec 01, 2009
Posts: 53
Milutin Markovic wrote:...
I'm trying to get a JTextPane to adjust its height according to whatever content I feed it. All I can do is to set a fixed height in pixels using Dimension.
...

http://java-sl.com/tip_text_height_measuring.html

Hope this helps.

Regards,
Stas
Milutin Markovic
Greenhorn

Joined: Mar 18, 2010
Posts: 12
Thanks Stanislav Lapitsky. You help me a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Make JTextPane adjust height to content