• Post Reply Bookmark Topic Watch Topic
  • New Topic

Size of JLabel

 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • 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?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!