How to remove border around buttons?

Roman picture Roman · Apr 26, 2010 · Viewed 35.1k times · Source

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?

Answer

Eric Eijkelenboom picture Eric Eijkelenboom · Apr 26, 2010
Border emptyBorder = BorderFactory.createEmptyBorder();
yourButton.setBorder(emptyBorder);

For more details on borders see the BorderFactory