posted 20 years ago
I've exteneded a JFrame and overridden it's paint() method because I want to draw an image in the background and then display a component on top of it (label, button, etc). But my component is not displaying in the right place. It only displays in the top left corner, even though I've set the location to something else. I don't think I'm painting it right somehow.
Here's a snippet:
JLabel label1 = new JLabel("hello");
label1.setSize(150, 50);
label1.setLocation(200, 200);
...
public void paint(Graphics g)
{
Graphics offScreenGraphics = offScreenImage.getGraphics();
offScreenGraphics.drawImage(myImage, 0, 0, 800, 600, 0, 0, 800, 600, this);
paint(offScreenGraphics);
label1.paint(offScreenGraphics);
g.drawImage(offScreenImage, 0, 0, this);
offScreenGraphics.dispose();
}
Any help or suggestions much appreciated!!
Thanks,
D Taylor