TitledBorder中的标题崩溃 [英] Title collapse in TitledBorder

查看:113
本文介绍了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,而是围绕).

Borders 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆