[英]Icon position in JButton
Is there any posibility of changing Icon image posintion in JButton? 在JButton中是否有改变Icon图像位置的可能性?
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);
Have a look at JButton.setHorizontalAlignment(int align) 看看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.
AbstractButton的默认值是SwingConstants.CENTER,但是诸如JCheckBox之类的子类可能使用不同的默认值。
you can set: 你可以设置:
You can change the gap of the space between the icon and text with setIconTextGap(int)
. 您可以使用
setIconTextGap(int)
更改图标和文本之间的setIconTextGap(int)
。 In addition, aligning the contents of the JButton
towards the left may help with setHorizontalAlignment(SwingConstants.LEFT)
. 此外,将
JButton
的内容向左对齐可能有助于setHorizontalAlignment(SwingConstants.LEFT)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.