Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
  • 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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

569 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