Can I make Swing JButtons have smaller margins?

笑着哭i 提交于 2020-01-01 07:33:36

问题


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 similar, it just ends up eating the text caption, cutting it off to the right. But it does not reduce the margins.


回答1:


I believe setMargin is what you're looking for.

myButton.setMargin(new Insets(0, 0, 0, 0));



回答2:


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



来源:https://stackoverflow.com/questions/1954674/can-i-make-swing-jbuttons-have-smaller-margins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!