aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes dynamic size of label Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "dynamic size of label" Watch "dynamic size of label" New topic
Author

dynamic size of label

swapnel surade
Ranch Hand

Joined: Mar 05, 2009
Posts: 129
Hello guys,

I want to show a label but its size should get reduced or expand as per size of text as that label will contain different languages.
is it possible to change label size dynamically ?

thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Yes, of course it is. You can add Listeners to your top-level container which show their size, and alter the display accordingly. You can add listeners to the text on a label and alter its size depending on the text. You will probably end up with a dreadful GUI . . . but you can do it.
swapnel surade
Ranch Hand

Joined: Mar 05, 2009
Posts: 129
layout of my gui is null. so its not a problem. Problem is I have to change the size using setBounds().
can you please tell me to which container I have to add listener just pseudo code..


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Don't use a null layout if you can help it. You add it to whichever container you happen to be using.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you add the label to a JPanel, with default FlowLayout,
and the panel has sufficient room, the label size will change
according to the length of the text.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: dynamic size of label