本文介绍了我可以让Swing JButton的边距更小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我更喜欢边距最小的按钮,与文本标题一样宽。有没有办法在Swing中的JButton中实现呢?
I prefer buttons with minimal margins, about as wide as their text caption. Is there a way to achieve that in a JButton in Swing?
我现在在实践中看到的是,即使我尝试使用setMaximumSize()和类似的,它最后吃掉了文字标题,把它切成了右边。但它并没有降低利润率。
What I am seeing in practice now is that even if I try to use setMaximumSize() and similar, it just ends up eating the text caption, cutting it off to the right. But it does not reduce the margins.
推荐答案
我相信是你要找的是什么。
I believe setMargin
is what you're looking for.
myButton.setMargin(new Insets(0, 0, 0, 0));
这篇关于我可以让Swing JButton的边距更小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!