Java 我可以让 Swing JButtons 有更小的边距吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1954674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I make Swing JButtons have smaller margins?
提问by EndangeringSpecies
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?
我更喜欢具有最小边距的按钮,大约与它们的文本标题一样宽。有没有办法在 Swing 的 JButton 中实现这一点?
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.
我现在在实践中看到的是,即使我尝试使用 setMaximumSize() 和类似的方法,它最终也会吃掉文本标题,将其从右侧切掉。但它并没有减少利润。
采纳答案by Michael Myers
回答by UnixNerd
Worth noting you can make the values for Insets -ve. This makes things even more compact and if done carefully doesn't look unpleasant.
值得注意的是,您可以为 Insets -ve 设置值。这使事情变得更加紧凑,如果仔细完成,看起来不会令人不快。