Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Setting JLabel width to the length of Text for specific font

807606Mar 4 2007 — edited Mar 4 2007
Hi.

I want to be able to set the width of a JLabel (or other component) so that a JLabel will be long enough to display the whole Text value.

If using a font where there is a fixed pixel width for each letter value, it would be easy to;
label.setWidth(myString.length()*3);
however, I'd like to use a font that doesn't have a fixed pixel width.
Is there a way to do this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 1 2007
Added on Mar 4 2007
3 comments
529 views