hi all,
please help me on how to create an imageButton ( image on top of a button). So when I click the button, it do some action.
This is my code. Please help me continue from this
import java.awt.image.BufferedIma
ge;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.*;
public class ImageLoading {
private JScrollPane getContent(BufferedImage image) {
ImageIcon icon = new ImageIcon(image);
JLabel label = new JLabel(icon);
label.setHorizontalAlignme
nt(JLabel.
CENTER);
return new JScrollPane(label);
}
public static void main(String[] args) throws IOException {
String path = "images/cougar2.jpg";
URL url = ImageLoading.class.getReso
urce(path)
;
BufferedImage image = ImageIO.read(url);
JFrame f = new JFrame();
f.setDefaultCloseOperation
(JFrame.EX
IT_ON_CLOS
E);
f.setContentPane(new ImageLoading().getContent(
image));
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
}
}
thanks.
Start Free Trial