Sized TitledBorder ?

Hello ?Can i choose the size (height and width) of a TitledBorder ?Thanks !
[96 byte] By [SnowFalcona] at [2007-11-27 5:49:30]
# 1
What do you mean? Line thickness? Yes, by using the BorderFactory methods provided.Bounds.... yes and no. It's based on the size of the component the border is being drawn on.
bsampieria at 2007-7-12 15:36:07 > top of Java-index,Desktop,Core GUI APIs...
# 2

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 !

SnowFalcona at 2007-7-12 15:36:07 > top of Java-index,Desktop,Core GUI APIs...
# 3
l1.setBorder(BorderFactory.createCompoundBorder(titel1, BorderFactory.createEmptyBorder(20, 1, 20, 1)));
bsampieria at 2007-7-12 15:36:07 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thank you very much !
SnowFalcona at 2007-7-12 15:36:07 > top of Java-index,Desktop,Core GUI APIs...
# 5
I have a problem,When i put a text in the label, the dimension of the border change.An idea ?Message was edited by: SnowFalcon
SnowFalcona at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 6
new JLabel("Label 1", JLabel.LEFT);you should learn to read the API docs.
bsampieria at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 7
I modified my question.
SnowFalcona at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 8

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.

bsampieria at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 9
Yes yes, i will add others labels into the border.Can you write me a piece of code for the Plain TitledBorder ?Thanks !
SnowFalcona at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 10
its like your first post.
bsampieria at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 11
Ok ! But, PlainTitledBorder is an unknow class.
SnowFalcona at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 12
I mean that i have an error "cannot fin symbol class PlainTitledBorder"
SnowFalcona at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 13

> 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)));

petes1234a at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...
# 14
Done !Thank you all !
SnowFalcona at 2007-7-12 15:36:08 > top of Java-index,Desktop,Core GUI APIs...