本文介绍了JButton 中的图标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能更改 JButton 中的图标图像位置?
Is there any posibility of changing Icon image posintion in JButton?
这是现在的样子:
我想将图标向左移动更多.
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);
推荐答案
解决方案
我已经向 myButton 添加了一个空边框(您可以添加任何类型的边框),现在它看起来像这样:
I've added an empty border(you can add any type of border) to the myButton and now it look like that:
代码:
myButton.setBorder(BorderFactory.createEmptyBorder(4, 4, 2, 20));
这篇关于JButton 中的图标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!