• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamic size of label

 
swapnel surade
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49841
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49841
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic