Here is my code :
TitledBorder title1;
Border blackline = BorderFactory.createLineBorder(Color.black);
title1 = BorderFactory.createTitledBorder(blackline, "Border");
title1.setTitleJustification(TitledBorder.LEFT);
JLabel l1 = new JLabel("Label 1");
l1.setBorder(title1);
And i get this :
http://img71.imageshack.us/img71/3769/01jf5.png
But, i want this :
http://img76.imageshack.us/img76/941/02ht1.png
Thanks !
The border doesn't change, the contents do.
An alternative way to handle what you want would be use the plain titled border (without the compound border) and set the label's preferred and/or minimum size to something that is what you want. Then it'll make the border along the edge and the text won't cause a resize.
But frankly, the usual reason for using a titled border is to group a set of components, not on a single label. Not sure what sort of UI experience you are going for here.
> I mean that i have an error "cannot fin symbol class
> PlainTitledBorder"
my guess is that he means a plain (normal) TitledBorder and not a compound border such as this one:
l1.setBorder(BorderFactory.createCompoundBorder(titel1, BorderFactory.createEmptyBorder(20, 1, 20, 1)));