I have an app that extends JFrame in which I add a JDesktopPane, and in that
I have a
couple of JInternalFrames that I use. In the main winow of the app (the
content pane of the JFrame if I am correct) I would like to put a tiled
image to serve as the background. I thought I was doing it correctly, but
nothing shows up. I created an ImagePanel class that extends JPanel, which
is listed below.
I create a panel of the ImagePanel type and added it to the content
pane of JFrame (in the constructor of my app) by doing the following:
ImagePanel imagePanel = new ImagePanel();
imagePanel.setVisible(true);
Container content = getContentPane();
content.add(imagePanel);
I then go on to add the desktop and the internal frames. This doesn't seem
to work. Is there a flaw in my understanding on how to do this?
Thanks in advance.
Ken
class ImagePanel extends JPanel
{
private Image image;
public ImagePanel()
{
image = Toolkit.getDefaultToolkit().getImage("foobar.gif");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image,0);
try
{
tracker.waitForID(0);
}
catch (InterruptedException exception)
{
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int imageWidth = image.getWidth(this);
int imageHeight = image.getHeight(this);
g.drawImage(image, 0, 0, null);
// tile the image
for(int i = 0; i * imageWidth <= getWidth(); i++)
{
for(int j = 0; j * imageHeight <= getHeight(); j++)
{
if (i + j > 0)
{
g.copyArea(0,0,imageWidth,imageHeight,i*imageWidth,j*imageHeight);
}
}
}
}
}
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing