开发者

Can I make Swing JButtons have smaller margins?

开发者 https://www.devze.com 2022-12-15 04:58 出处:网络
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?

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?

What I am seeing in practice now is that even if I try to use setMaximumSize() and s开发者_开发百科imilar, 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));


Worth noting you can make the values for Insets -ve. This makes things even more compact and if done carefully doesn't look unpleasant.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号