Maybe it is not possible, but i'm just wonderring, if it's possible and if there is an easy to do this : i have a button with icon, and my icon is in circle shape, but button is quadratic, so i would like to leave visible only icon, and make clickable only the icon, not the whole hidden button. Is it possible ? And if it is, maybe there is another easy way to do this ?
I.e., i have a button http://s23.postimg.org/bf7n6j397/aaa.png , red is my icon, and blue is the rest of the button, and want to make a blue area unclickable, only red would act as a button. The point is that i want a circle button.
My code is something like that :
import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.Insets; class ImageButton extends JButton { public ImageButton(String img) { this(new ImageIcon(img)); } public ImageButton(ImageIcon icon) { setIcon(icon); setMargin(new Insets(0, 0, 0, 0)); setIconTextGap(0); setBorderPainted(false); setOpaque(false); setBorder(null); setText(null); setSize(icon.getImage().getWidth(null), icon.getImage().getHeight(null)); } } final ImageButton button = new ImageButton("http://www.javaprogrammingforums.com/images/Default.png");