createImage problem
Hi,
I'm trying to create an Image of a swing component
and then display that Image. It seems that createImage
doesn't really create anything.
The following program demonstrates my problem:
import java.awt.*;
import javax.swing.*;
public class ImageViewer
{
JFrame i_mainFrame, jf2;
JButton i_button;
public ImageViewer()
{
i_button = new JButton("BIG BUTTON");
i_mainFrame = new JFrame("Main Frame");
i_mainFrame.getContentPane().add(i_button);
i_mainFrame.pack();
i_mainFrame.setVisible();
makeCopy();
}
public void makeCopy()
{
Image i = i_button.createImage(i_button.getSize().width, i_button.getSize().height);
jf2 = new JFrame("JF2");
jf2.getContentPane().paint(i.getGraphics());
jf2.pack();
jf2.setVisible(true);
}
public static void main(String[] args)
{
ImageViewer iv = new ImageViewer();
}
}
note that even if I change the line
Image i = i_button.createImage.....
to
Image i = i_mainFrame.createImage(i_mainFrame.getSize().width, i_mainFrame.getSize().height);
it doesn't work either.
I also can't use toolkit.createImage because the api
doesn't allow to create an image from a swing component.
Help would be greatly appreciated.

