EightSquared
EightSquared

Reputation: 37

remove default border from JButton

Hi just a quick question. I want to remove the ugly grey border the JButtons create.

http://gyazo.com/e9f57308190e1b6d49ac7b300fce2a4b

    setBackground(null);
    .setOpaque(false);
    .setBorderPainted(false);

none of these work, im sure it's a one liner, any help appricated.

Upvotes: 0

Views: 2362

Answers (2)

mvreijn
mvreijn

Reputation: 2942

As far as I know you can use the setBorder() method for this. Something along these lines should work:

Border noBorder = new LineBorder(Color.WHITE, 0);
JButton borderlessButton = new JButton("No Border");
borderlessButton.setBorder(noBorder);

Upvotes: 2

MadProgrammer
MadProgrammer

Reputation: 347204

I think you're looking for a combination of JButton#setContentAreaFilled and JButton#setBorderPainted

You might also like to use JButton#setFocusPainted as well

For example, example and example

Upvotes: 2

Related Questions