• Post Reply Bookmark Topic Watch Topic
  • New Topic

JLabel alignment  RSS feed

 
Dalia Sultana
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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?
 
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 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.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!