I'm building a JFrame with an image as a background. I'm overriding the paint() method to draw that image in the JFrame, but when I start the application in Eclipse, none of the JComponents I added are visible. Here's my SSCCE:
public class foo extends JFrame{
Image i = ImageIO.read(new URL("http://pittsburgh.about.com/library/graphics/regatta_balloons-640.jpg"));
foo(){
setSize(100, 100);
add(new JButton("Foo"));
setVisible(true);
}
@Override public void paint(Graphics g){
super.paint(g);
g.drawImage(i, 0, 0, null);
}
}
Don't override the paint() method of JFrame!!! That is NOT how custom painting is done.
If you are trying to add a background image to your frame then check out Background Panel for a couple of approaches.