I used the following method try to get a BufferedImage from a non light weight Component, but I got a black image, so it didn't work, the component I passed to it is a WebBrowser object from JDIC, it's a non light weight Component :
public static BufferedImage getComponentImage(Component aComponent,Rectangle region) throws IOException
{
BufferedImage image= new BufferedImage(aComponent.getWidth(),aComponent.getHeight(),BufferedImage.TYPE_INT_RGB);
Graphics2D g2d=image.createGraphics();
SwingUtilities.paintComponent(g2d,aComponent,aComponent.getParent(),region);
g2d.dispose();
/*
Graphics g = image.getGraphics();
aComponent.paint(g);
// aComponent.paintAll(g);
// SwingUtilities.paintComponent(g,aComponent,aComponent.getParent(),region);
g.dispose();
*/
return image;
}
I've also tried the lines in comments, they didn't work either, so how to capture a BufferedImage from a non light weight Component in java ?