TitledBorder中的标题崩溃 [英] Title collapse in TitledBorder
问题描述
我有一个TitledBorder,其标题大于正文. 它被切开,其长度根据身体的最大长度进行设置.
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.
假设我在正文中有一个标签TEST
,并用标题为TESTING TITLE
的TitledBorder括起来.
在这种情况下,标题将被剪切并显示为TESTI
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
我正在为主体使用MigLayout.
I'm using MigLayout for the body.
无论标题内容如何,都可以显示完整标题吗?
Any way to the show the full title irrespective to the content it contains?
推荐答案
Border
并不直接参与LayoutManager
的尺寸评估(它们本身不是JComponent
,而是围绕
Border
s don't directly participate in size evaluation by the LayoutManager
(they are not a JComponent
themselves but just decorations around a JComponent
).
因此,确保TitledBorder
中的标题完全可见的唯一方法是确保为其分配的面板(或该面板中嵌入的组件)的最小尺寸.
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).
在这种情况下,最小尺寸的计算应基于TitledBorder
的当前标题和TitledBorder
用来绘制其标题的Font
.
Minimum size calculation should in this case be based on the current title of your TitledBorder
and the Font
used by TitledBorder
to paint its title.
说实话,我不确定所有这些工作是否值得写.
To be honest, I am not sure, all this work is worth writing.
根据TitledBorder
中包含的确切组件,一个更简单的解决方案是使用JTextField.setColumns(n)
,其中n与标题相比足够大.
Based on the exact components comntained inside your TitledBorder
, a simpler solution would be to use JTextField.setColumns(n)
where n is big enough compared with the title.
实际上,如 JGoodies 的Karsten Lentszch所建议的那样,一种更好的方法是完全避免使用TitledBorder
.名声,并用彩色的JLabel
和水平的JSeparator
代替,它将完全参与布局并因此用于尺寸计算.
Actually a better way would be to avoid TitledBorder
altogether, as suggested by Karsten Lentszch from the JGoodies fame, and replace it with a colored JLabel
and a horizontal JSeparator
, that would fully participate in the layout and hence be used for size computation.
这篇关于TitledBorder中的标题崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!