Reputation: 2534
Is there any posibility of changing Icon image posintion in JButton?
This is how it looks now:
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);
Upvotes: 4
Views: 10998
Reputation: 2534
SOLUTION
I've added an empty border(you can add any type of border) to the myButton and now it look like that:
Code:
myButton.setBorder(BorderFactory.createEmptyBorder(4, 4, 2, 20));
Upvotes: 2
Reputation: 5496
You can change the gap of the space between the icon and text with setIconTextGap(int)
. In addition, aligning the contents of the JButton
towards the left may help with setHorizontalAlignment(SwingConstants.LEFT)
.
Upvotes: 3
Reputation: 910
Have a look at JButton.setHorizontalAlignment(int align)
Sets the horizontal alignment of the icon and text. AbstractButton's default is SwingConstants.CENTER, but subclasses such as JCheckBox may use a different default.
you can set:
Upvotes: 3