Question

I have a desktop application having heavyweight components (JxBrowser) in a JFrame. How can I make a snapshot from the GUI and save it to for example a png file?

Note: The method using Graphics2d and Component.paint()/paintAll()/print/printAll works only for lightweight components.

Any answers appreciated!

EDIT

I have already tried this:

robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); 

But I want the inner component to be captured...

EDIT

The situation seems to converge to this solution: if I have a bigger heavyweight component in my JFrame, so it is rendered on a JScrollPane then there exist no other method to get a snapshot of it programatically then to scroll it/screenshot it with screencapture?

Was it helpful?

Solution

My name is Roman and I'm developer at TeamDev.

JxBrowser component it's a heavyweight component that embedds a native mozilla window to display web pages. To get screenshot of a full web page from JxBrowser component you can really use the Java Robot functionality with web page scrolling. For small web pages this solution is ok. But receiving screenshot of a large web page will take a lot of time. Also please note that Java Robot allows capturing only screen. So if some window will appears over the JxBroser component, then it will be captured too.

We have already started working on this functionality in terms of JxBrowser project. The solution that will allow capturing a full web page including its invisible part is based on Mozilla internal stuff. You will be able to capture a full web page and save it as image very easy.

We are going to add this functionality in one of the next release of JxBrowser library, but the release date is not defined yet. If you wish you can subscribe to TeamDev's RSS feed: http://support.teamdev.com/blogs/feeds/tags/company_news

Or just let me know and I will inform you when this functionality will be available. Please let me know if you have any further questions. I will be happy to help.

Regards, Roman

OTHER TIPS

You mean programmatically?

What about

Point p = yourAwtComponent.getLocationOnScreen();
int w   = yourAwtComponent.getWidth();
int h   = yourAwtComponent.getHeight();

Rectangle rectangle = new Rectangle( p.x, p.y, w, h );

Image image = robot.createScreenCapture(rectangle);

And then something like this:

ImageIO.write( image, "png", file );

JxBrowser API provides functionality that allows saving the whole web page as PNG image. Please see the sample.

You can try also to create a screenshot by implementing this:

    int width = frameContainer.getWidth();
    int height = frameContainer.getHeight();

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();

    frameContainer.paint(g2);

    return image;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top