TitledBorder 中的标题折叠
我有一个 TitledBorder ,其标题大于正文。 它被削减,长度根据身体的最大长度设定。
假设我在正文中有一个标签,上面写着 TEST
,并且它被标题为 TESTING TITLE
的 TitledBorder 括起来。 在本例中,标题被缩短并显示为 TESTI
我正在使用 MigLayout 作为正文。
有什么方法可以显示完整的标题,无论其包含的内容如何?
I've a TitledBorder having title larger than the body.
Its get cut down and the length sets as per the maximum length of the body.
Suppose I have a label in the body saying TEST
and its enclosed by TitledBorder having title TESTING TITLE
.
In this case the title is cut down and displayed as TESTI
I'm using MigLayout for the body.
Any way to the show the full title irrespective to the content it contains?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Border
不直接参与LayoutManager
的大小评估(它们本身不是JComponent
,而只是JComponent 周围的装饰)。
因此,确保 TitledBorder 中的标题完全可见的唯一方法是为其分配的面板(或者更确切地说是嵌入在该面板中的组件)确保最小尺寸。
在这种情况下,最小大小的计算应基于
TitledBorder
的当前标题以及TitledBorder
用于绘制其标题的Font
。说实话,我不确定,所有这些作品是否值得写。
根据
TitledBorder
中包含的确切组件,更简单的解决方案是使用JTextField.setColumns(n)
,其中 n 与标题相比足够大。实际上,更好的方法是完全避免使用
TitledBorder
,正如来自 JGoodies 名声,并将其替换为彩色JLabel
和水平JSeparator
,它将完全参与布局,因此可用于尺寸计算。Border
s don't directly participate in size evaluation by theLayoutManager
(they are not aJComponent
themselves but just decorations around aJComponent
).Hence the only way to ensure that the title in a
TitledBorder
is completely visible is to enfore a minimum size for the panel it is assigned (or rather for components embedded in that panel).Minimum size calculation should in this case be based on the current title of your
TitledBorder
and theFont
used byTitledBorder
to paint its title.To be honest, I am not sure, all this work is worth writing.
Based on the exact components comntained inside your
TitledBorder
, a simpler solution would be to useJTextField.setColumns(n)
where n is big enough compared with the title.Actually a better way would be to avoid
TitledBorder
altogether, as suggested by Karsten Lentszch from the JGoodies fame, and replace it with a coloredJLabel
and a horizontalJSeparator
, that would fully participate in the layout and hence be used for size computation.我发现添加适当宽度的水平支柱将强制面板调整大小,以便显示整个标题:
我确信可能有一种方法可以在运行时动态找到所需的宽度,但我只是这样做懒惰的方法:将其设置为覆盖我的 TitledBorder 标题文本大小的宽度。
I have found that adding a Horizontal Strut of an appropriate width will force the panel to resize so that it shows the entire title:
I'm sure there is probably a way to dynamically find the desired width at runtime, but I just do it the lazy way: set it to a width that covers the size of my TitledBorder title text.
这对我来说效果很好:
This works well for me: