Modify a website 'screen capture' program, to remove javascript 'errors'

Posted on 2005-03-08
Medium Priority
Last Modified: 2008-02-01
The program below is designed to do a 'screen capture' of a whole webpage. It uses a text area to accomplish this. The problem is that if the webpage has javascript on it, it will show up as errors. I am looking to modify this program so that the errors are not displayed. If the way to do this is to not use a text area, this is fine. If using a browser would be better, that is ok as well. In the end, I just need the image of the whole web page. The test url (CNN) is just a popular page that has javascript on it. If you could help out, it would be greatly appreciated. If you have any questions, please let me know.

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.net.*;
public class SavingAScrollingComponent
    public SavingAScrollingComponent()
        JEditorPane textArea = getTextArea();
        JFrame f = new JFrame();
        f.getContentPane().add(getUIPanel(textArea), "North");
        f.getContentPane().add(new JScrollPane(textArea));

    private void save(Component c)
        int w = c.getWidth();
        int h = c.getHeight();
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        File file = new File("scrollingComponent.png");
            ImageIO.write(image, "png", file);
        catch(IOException ioe)
            System.err.println("write: " + ioe.getMessage());
    private JPanel getUIPanel(final JEditorPane ta)
        JButton save = new JButton("save");
        save.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
        JPanel panel = new JPanel();
        return panel;
    private JEditorPane getTextArea()
        JEditorPane ta = new JEditorPane();
        ta.setMargin(new Insets(0,5,0,5));
          URL file = new URL("http://www.cnn.com/");
        catch(IOException ioe)
            System.err.println("read: " + ioe.getMessage());
        return ta;
    public static void main(String[] args)
        new SavingAScrollingComponent();
Question by:stakor
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 13493540
hi stakor,
  using JEditorPane, you cannot render javascript.
 Try using webrender. http://www.webrenderer.com/ [but it is shareware ]

  see this link http://www.jguru.com/faq/view.jsp?EID=25662 


Hope this helps

Author Comment

ID: 13499828
I fear that I neglected to mention how much of a newbie I am to Java. I see that the general idea here is to replace the JEditorPane with a java web browser. But, that is about as far as I get...

In the example that you provide, I see that there is a new object called SormBase, and that it is using Swing. Now keep in mind I only know that there are books writien on swing, but I know nothing about it. (Actually I think it is a method for communicating between objects? - I really don't know) After that there is a new JPannel, and a viewport is created via Storm Base's Storm Panel.

I guess my major problem here (other than not knowing much Java) is that I don't fully understand how to replace the JEditorPane in 'my' application. I am not even certain where I need to place the ICE browser's jb.class in relation to my application. Does it only need to be visable in the path, or does it need something more specific? Sorry, should have mentioned I am very new to Java.

Accepted Solution

durgaprasad_j earned 2000 total points
ID: 13503786
           would you be able to put any of the given browser software in your application /?
           If you have done it, saving part is same. Instead of sending JLabel, just send that component to save function.

           If you have n't got how to mix your program with that software, i will try and let you know tomorrow.
           BTW  Follow these steps:
                         JEditorPane is a class. Like this , any api has a starting class, using that you can display web pages.
                         You are adding JEditorPane into JFrame. Similarly here also, add that browser object instead of JEditorPane to JFrame .

                         Just think of that browser object as something alternative for JEditorPane. [ it is simple, dont get afraid of this]

Hope this helps

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question