Hi! Could someone please give me any idea on how to add a background image to JInternalFrame without subclassing. Below I provide a code snippet, but the line jif.setBackgroundImage(backImage);
is incorrect. Please, help me to fix this error. But I don't want to create a subclass, e.g. MyJInternalFrame. Thanks!
JInternalFrame jif = new JInternalFrame("Title", true, true, true, true) {
private Image backgroundImage = null;
public void setBackgroundImage(Image backgroundImage) {
this.backgroundImage = backgroundImage;
}
protected void paintComponent(Graphics g) {
if (isOpaque()) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
}
if (backgroundImage != null) {
g.drawImage(backgroundImage,0,0,this);
}
}
};
ImageIcon icon = new ImageIcon(SelectablePanel.class.getResource("/icons/bkg_palette.jpg"));
Image backImage = icon.getImage();
jif.setBackgroundImage(backImage); // THIS LINE PROVIDES A COMPILATION ERROR
...
The following is the compilation error: "cannot find symbol symbol: method setBackgroundImage(java.awt.Image)"