It will work:
List list... // I don't know exactly what it is, but it should extand Container or Component
Container mainComponent = new Container(){
public void paint(Graphics g) {
//draw bg image
super.paint(g);
}
};
mainComponent.add(list);
I suppose your mistake is like one of discribed below:
1. in a method paint you invoke super.paint() before background image drawing
2. you add component which contains bgImage after adding list component
I believe that my code is right..
I extends List component and override the paint method.
First, I draw the image, then I call the super method.
Then, in a main method I add the list to a panel.
Where I'm wrong?
import java.awt.Graphics;
import java.awt.Image;
import java.awt.List;
import java.awt.Toolkit;
public class ListBg extends List{
private static final long serialVersionUID = 1L;
Image image;
public ListBg(){
super();
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage("C:/Programmi/image.jpg");
}
public void print(Graphics g){
g.drawImage(image,0,0,this);
super.print(g);
}
}
> public void print(Graphics g){
> g.drawImage(image,0,0,this);
> super.print(g);
> }
> }
you should override method
public void paint(Graphics g){};
not print as you do.
In a case it was just mispaint share your whole class text for tests...