How to remove border around buttons?

久未见 提交于 2019-11-29 17:49:18

问题


I have a JPanel with the GridLayout. In every cell of the grid I have a button. I see that every button is surrounded by a gray border. I would like to remove these borders. Does anybody know how it can be done?


回答1:


Border emptyBorder = BorderFactory.createEmptyBorder();
yourButton.setBorder(emptyBorder);

For more details on borders see the BorderFactory




回答2:


yourButton.setBorderPainted(false);




回答3:


In most recent Java versions it's necessary to call setContentAreaFilled(false) to remove the border entirely. Add an empty border for some padding:

button.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
button.setContentAreaFilled(false);



回答4:


I think it's very likely the borders are part of the buttons' GUI. You could try calling .setBorder(null) on all the buttons and see what happens!




回答5:


It can be like this:

yourButton.setBorder(null);


来源:https://stackoverflow.com/questions/2713190/how-to-remove-border-around-buttons

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