如何制作与文本大小完全相同的按钮? [英] How can I make a button exactly the same size of its text?

查看:144
本文介绍了如何制作与文本大小完全相同的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使 JButton 完全取其文本的大小?因为默认情况下, JButton 在其文本周围会有少量填充(水平和垂直)。我想删除那个填充。

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 padding.

推荐答案

JButton 有边框默认情况下,你可以删除它:

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

button.setBorder(null);






如果你想保留边框,请减少保证金(参见 Eugenes回答

这篇关于如何制作与文本大小完全相同的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆