开发者

How can I make a button exactly the same size of its text?

Is it possible to make a JButton take exactly the size of its text? Since by default, a JButton will have a small amount of padding (both horizontal and vertical) around its text. I would like to remove that paddin开发者_如何学运维g.


JButton has a border by default, you can remove it:

button.setBorder(null);

If you want to keep the border, reduce the margin (see Eugenes answer)


Clear out the margins in the button with setMargin.

Removing the border has the side-effect of removing the border. If you only want to clear out the margins, use the setMargin method to set the margins all to zero.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜