• 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

JLabel alignment

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jlabel as a rendering component for a JTable, it shows some text and an icon. I want the text to appear on the right side and the icon on the left. If I call setHorizontalAlignment on the label, everything goes to the right. Any ideas?
 
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 Dalia Sultana:
I have a jlabel as a rendering component for a JTable, it shows some text and an icon. I want the text to appear on the right side and the icon on the left. If I call setHorizontalAlignment on the label, everything goes to the right. Any ideas?



setHorizontalAlignment sets the alignment of the label contents (text and icon if any)
setHorizontalTextPosition sets the position of the text with relation to the icon.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which probably means that it the text is located to the left or right of the icon.

Perhaps you should stop using a JLabel but use a JPanel instead. Give it a BorderLayout, add a JLabel with the icon using BorderLayout.LEFT and a JLabel with the right aligned text using BorderLayout.RIGHT.
reply
    Bookmark Topic Watch Topic
  • New Topic