使JTextPane调整内容的高度 [英] Make JTextPane adjust height to content
本文介绍了使JTextPane调整内容的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取JTextPane
来根据我提供的任何内容来调整其高度.我所能做的就是使用Dimension(像素)设置固定的高度(以像素为单位).
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.
如何使JTextPane
折叠/展开,使其适合内容?
How do I make the JTextPane
collapse/expand so it will fit to contents?
我可能会补充说,我在已添加到JScrollPane
的GridBagLayout
编辑的JPanel
中使用它.
I might add that I use this in a GridBagLayout
'ed JPanel
that has been added to a JScrollPane
.
推荐答案
JTextPane tp = new JTextPane();
setLayout(new BorderLayout()); // set layout on parent
add(tp, BorderLayout.CENTER);
这对我有用.
这篇关于使JTextPane调整内容的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文