Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to remove underlying JButton image?

843806Jul 14 2007 — edited Jul 30 2007
Hi

I have this code to place an image over the standard JButton. But if the image is smaller or transparent, the underlying standard image is still seen. Is it possible to remove this image and just have the background of the panel showing?
public class ImageButton extends JButton {

	public ImageButton(ImageIcon icon, String text) {
		setSize(icon.getImage().getWidth(null),
			icon.getImage().getHeight(null));
		setIcon(icon);
		setMargin(new Insets(0,0,0,0));
		setIconTextGap(0);
		setBorderPainted(false);
		setBorder(null);
		setText(text);
                setHorizontalTextPosition(this.CENTER);
	}
/code]

Thanks for any help.
Chris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2007
Added on Jul 14 2007
11 comments
289 views