3sdmx 3sdmx - 3 months ago 15
Java Question

Java: using an image as a button

I would like to use an image as a button in Java, and I tried to do this:

BufferedImage buttonIcon = ImageIO.read(new File("buttonIconPath"));
button = new JButton(new ImageIcon(buttonIcon));


But this still shows the actual button behind the image, I would only like the image to function as the button, how can I do this?

Thanks in advance.

EDIT: SOLUTION FOUND

A combination of jzd answer and something else I found solved the problem:

button.setBorder(BorderFactory.createEmptyBorder());
button.setContentAreaFilled(false);


This did the trick for me, thanks for your answers!

jzd jzd
Answer

Remove the border like so:

button.setBorder(BorderFactory.createEmptyBorder());
Comments