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?
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.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: