How can i set the background of JComponent ? I currently have this class :
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JComponent;
public class ImagePanel extends JComponent {
/**
*
*/
private static final long serialVersionUID = 1L;
private Image image;
public ImagePanel(Image image) {
this.setLayout(new BorderLayout());
this.image = image;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this);
}
}
private BufferedImage myImage;
private JButton button = new JButton("Click");
try {
myImage = ImageIO.read(new File("/images/picture.png"));
} catch (IOException e) {
e.printStackTrace();
}
I used the following code to paint the JFrame's content pane, but i don't know how to do it for a JButton