Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 511
Paludan Avatar asked Dec 13 '13 12:12

Paludan


2 Answers

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);
like image 131
mKorbel Avatar answered Oct 24 '22 12:10

mKorbel


You just missed a line.

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

like image 33
Prasad Avatar answered Oct 24 '22 13:10

Prasad