Search code examples
javaswingjbuttonimageicon

Icon position in JButton


Is there any posibility of changing Icon image posintion in JButton?

This is how it looks now:

enter image description here

I want to move the icon more to the left.

I have tried to change the text alignment but it doesn't work as I want:

myButton.setHorizontalTextPosition(SwingConstants.RIGHT);

Solution

  • SOLUTION

    I've added an empty border(you can add any type of border) to the myButton and now it look like that:

    enter image description here

    Code:

    myButton.setBorder(BorderFactory.createEmptyBorder(4, 4, 2, 20));