1

I added an icon to my label:

label.setIcon(myIcon);
label.setHorizontalTextPosition(SwingConstants.LEFT);

Now I have a text which has right alignment and then I have an icon. But how can I align the icon to the right side and the text to the left?

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
void
  • 731
  • 2
  • 11
  • 26
  • Try `label.setHorizontalAlignment(SwingConstants.LEFT);`. I'm not sure that you can align the text and icon differently in one JLabel. – BoDidely Aug 13 '15 at 14:48
  • That does align the text to the left and icon to the right. If this doesn't work then post a proper [SSCCE](http://sscce.org/) demonstrating the problem. If you are trying to create a large gap between the two then you can set the "gap". If you want the gap to be variable depending on the width of the frame, then you need two components with a different layout manager, maybe a `BorderLayout` and add one component to the `LINE_START` and the other to `LINE_END`. – camickr Aug 13 '15 at 14:48
  • Possible [duplicate](http://stackoverflow.com/q/2932389/230513). – trashgod Aug 13 '15 at 15:48

0 Answers0