Search code examples
javaswingjbutton

Java JButton only image?


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


Solution

  • 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);