• 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

Size of JLabel

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I create few JLabels. While creating it, the name is big (as it represents the file path) Any ideas on how to display in a copact manner or even make it like 2 lines instead of one long line. Any custom arrangements can be done?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gopu Akraju:
I create few JLabels. While creating it, the name is big (as it represents the file path) Any ideas on how to display in a copact manner or even make it like 2 lines instead of one long line. Any custom arrangements can be done?



Swing supports HTML tags. You can try using something like

Of course you can enhance it more. In case your display text is dynamic, you might want to put it in an HTML table or something. That way you wont have to worry about where to break the text. The HTML table will automatically do it for you.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestion. In the same example what you have mentioned

Is there any way to do like
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gopu Akraju:



There was a post some days back regarding the same stuff but for JTables.
You might want to search for it and piggy back on the solution.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gopu Akraju:
Thanks for the suggestion. In the same example what you have mentioned

Is there any way to do like



JLabel already does that, except on the other side: My label text is so...

If you're not seeing it, then there may be other layout issues afoot.

If you want to change it to put the ellipsis on the left instead of the right, you can override BasicLabelUI.layoutCL() but unfortunately it looks nontrivial to do so unless you happen to be using a fixed-width font.
 
reply
    Bookmark Topic Watch Topic
  • New Topic