9

I set the icon of my button to an .png I made in photoshop, but instead of just the image being visible, then there's still the button border or what ever you wish to call it.

enter image description here

I want the button to just be:

enter image description here

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Paludan
  • 622
  • 1
  • 5
  • 21
  • 1
    What Look&Feel are you using? You can remove borders, putting `Insets` in 0 – nachokk Dec 13 '13 at 12:40
  • This previous question may help you [link](http://stackoverflow.com/questions/18468169/is-there-any-way-to-fit-an-image-in-a-tab-component) – nachokk Dec 13 '13 at 12:42

3 Answers3

16

there are set of methods implemented in API that created undecorated JButton, e.g.

JButton button = new JButton();
button.setBorderPainted(false);
button.setBorder(null);
//button.setFocusable(false);
button.setMargin(new Insets(0, 0, 0, 0));
button.setContentAreaFilled(false);
button.setIcon(myIcon1);
button.setRolloverIcon(myIcon2);
button.setPressedIcon(myIcon3);
button.setDisabledIcon(myIcon4);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
3

You just missed a line.

i.e. btn.setBorder(null); is the only thing you need to do. Rest is perfect.

Prasad
  • 1,188
  • 3
  • 11
  • 29
0

Add this to make it perfect:button.setFocusPainted(false);

Juan Carlos Ibarra
  • 1,299
  • 14
  • 15