如何使包裹在JScrollPane中的JTextPane缩小以适合文本 [英] How to make JTextPane wrapped in JScrollPane shrink to fit the text
问题描述
我有一个带有HTML文本的JTextPane
.
I have a JTextPane
with HTML text.
我使用了GroupLayout
(使用WindowBuilder).
I used GroupLayout
(using WindowBuilder).
我将JFrame
的最小尺寸设置为800x600,因此用户不能使其小于此尺寸.
I've set the minimum size of my JFrame
to 800x600 so the user cannot make it smaller than that.
该应用程序滚动很大JPanel
整个窗口的大小.面板的顶部由包裹在JScrollPane
中的JTextPane
占据.我禁用了滚动条,并设置了JScrollPane
的大小以使整个文本可见.
The app has a big scrolling JPanel
the size of the entire window. The top part of the panel is taken up by a JTextPane
wrapped in JScrollPane
. I have disabled the scroll bars and sized the JScrollPane
to make the entire text visible.
在组布局中,JScrollPane
设置为在垂直方向上保持恒定,但在水平方向上保持不变.
In group layout the JScrollPane
is set to stay constant vertically, but size horizontally.
我的问题是,当用户使窗口变大时,JScrollPane
也会展开,但是现在在文本窗格的底部留有很大的空白.有没有一种方法可以使JTextPane
缩小以适合其内容.
My issue is that when the user makes the window larger the JScrollPane
also expands, but now there is a big white space left at the bottom of the text pane. Is there a way that I can make JTextPane
shrink to fit its contents.
如果您建议使用其他布局,我也愿意尝试.
Also if you suggest a different layout, I would be willing to try it.
推荐答案
我使用了@的 TextPanePerfectSize
示例camickr解决了类似的问题.该示例使用validate()
和pack()
调整为首选大小.您也许可以使其适应您的情况.
I used this TextPanePerfectSize
example from @camickr to solve a similar problem. The example uses validate()
and pack()
to adjust to the preferred size. You might be able to adapt it to your situation.
这篇关于如何使包裹在JScrollPane中的JTextPane缩小以适合文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!