• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Make JTextPane adjust height to content

 
Milutin Markovic
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stanislav Lapitsky. You help me a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic