Java JButton image only?

I set the icon of my button to .png, which I did in Photoshop, but instead of just seeing the image, then there is still a button frame or whatever you want to name.

enter image description here

I want the button to be simple:

enter image description here

+7
java swing jbutton
source share
3 answers

there is a set of methods implemented in the API that created unecorated JButton , for example

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); 
+13
source share

You just skipped a line.

i.e. btn.setBorder(null); - this is the only thing you need to do. The rest is wonderful.

+2
source share

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

0
source share

All Articles