How to add a horizontal gap with a JLabel

michelemarcon picture michelemarcon · Oct 1, 2008 · Viewed 13.2k times · Source

I have a JLabel (actually, it is a JXLabel).

I have put an icon and text on it.

<icon><text>

Now I wand to add some spacing on the left side of the component, like this:

<space><icon><text>

I DON'T accept suggestion to move the JLabel or add spacing by modifying the image.

I just want to know how to do it with plain java code.

Answer

michelemarcon picture michelemarcon · Oct 1, 2008

I have found the solution!

setBorder(new EmptyBorder(0,10,0,0));

Thanks everyone!