• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How To Make JLabel automatically wrap to next line

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JLabel text displayed in an Introductory text in a dialog. How can I make it fit in with the dialog width and automatically wrap to next line
nicely?
Right now, when the text is long, it changes my dialog size (width) to fit the text in. That make the dialog looks bad.
Is ther any better way to do this ? Maybe I should use JTextArea not JLabel?
Please help. Thanks!
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use HTML text as Label text to your label
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use HTML as Label text.
 
VIJAY Yadlapati
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use HTML for Label text. Here is the code sample
label.setText(<HTML> Line1<br> Line2</HTML>");
 
Frank Li
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi YIJAY,
Thanks for your reply. The HTML solution does not really help because I don't know where to break. My label could be very long and it is translatable. In different language, the length varies.
I have figured out that if I use JTextArea and
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
works for me.
Maybe there are better way to do so.
Thanks a lot!
 
Rancher
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use HTML <p> tags to make the text break wherever it needs to. For example...

This should do what you want.
[ October 20, 2004: Message edited by: Matthew Taylor ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LineBreakMeasurer
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic