It's not a secret anymore!*
The moose likes Beginning Java and the fly likes how to size a label? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to size a label?" Watch "how to size a label?" New topic
Author

how to size a label?

Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
hello all,
i am wondering if there is a way to create a label in the size you want.
e.g JLabel label0 = new JLabel("Year ", JLabel.RIGHT);
how to define its size you want???
Mindy
Thanks!
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Labels have a "preferred size" that the LayoutManager tries to respect. As a rule that is "just big enough to hold the String". The size of the string depends on the Font that you are using and the String itself of course. You can try to pad the label with spaces to add width.
The idea is that you really don't WANT to specify the size, because when it looks good on your machine it will look bad on the next O, or when the user messes with the size of the screen etc.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Mindy Wu
Ranch Hand

Joined: Jan 12, 2001
Posts: 121
Thank you Cindy!
 
Don't get me started about those stupid light bulbs.
 
subject: how to size a label?
 
Similar Threads
Resize width only?
Refresh
Image in JLabel
How to create a multiple line JLabel.
Putting a LABEL on a big IMAGE