JEditorPane + HTML = slow?

Hi,
I am trying to view HTML in my app in a JEditorPane. Everythings works fine except that it goes very slowly. My app generates HTML as a string that is about 65 kB in size. Then when the JEditorPane is going to display the HTML string it takes a very long time, maybe 3 seconds for each page (my computer has 2 CPUs 2.8 GHz and 2 GB RAM).
Anybody else with similay problems?

I wouldn't expect any JEditorPane support for HTML4 or XHTML any time soon. This bug report for example has been "in progress" for more than five years now!
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4296022
I can not find any evidence that there is any new support in Mustang:
http://www.java.net/download/jdk6/doc/api/

Similar Messages

  • Puting into JEditorPane HTML file

    I want to put into JEditorPane HTML file from my local drive.
    How to do that?

    Hear is example try it.
    *(c)pesilEX - 2007
    * [email protected]
    * Let�s make a open source software world
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.URL;
    public class pesilEX extends JFrame implements ActionListener{
    JPanel cp;
    // Declaring a url to get file name
    // Also this can use to get url form online
    public URL helpURL;
    JScrollPane scrol;
    JEditorPane htmlPane;
    JButton btn1;
    // This string is use to store file name
    String fileName;
    public pesilEX(){
         cp = (JPanel)getContentPane();
         cp.setLayout(null);
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    scrol = new JScrollPane();
    scrol.getViewport().add(htmlPane);
    scrol.setBounds(10,10,370,300);
    cp.add(scrol);
    btn1 = new JButton("View!");
    btn1.setBounds(260,320,120,20);
    cp.add(btn1);
    btn1.addActionListener(this);
    public void actionPerformed(ActionEvent e){
         if(e.getSource()==btn1){
         // File name you can replace is as you want
    fileName = "pesilEX/help.htm";
    // Import html file to java
         helpURL = getClass().getClassLoader().getResource(fileName);
    try{
    // Set url to JEditorPane
         htmlPane.setPage(helpURL);
    catch(Exception er){
         System.out.println(er.toString());
    public static void main(String[] args){
    pesilEX pesil = new pesilEX();
              pesil.setSize(400,400);
              pesil.setTitle("pesilEX JHtml viewer");
              pesil.setResizable(false);
              pesil.setVisible(true);
    }

  • JEditorPane HTML link in the same page

    Hi,
    I want to show an HTML page in JEditorPane.
    The HTML page have <a> tags that link to a bookmark in
    the same page, but I can�t show this because I get an error
    like this:
    MalformedURL or similiar.
    I try to do somethig like this:
    public void hyperlinkUpdate(HyperlinkEvent ev)
    ...Editor.setPage(ev.getURL());
    or
    ...Editor.setPage(ev.getDescription());
    without results.
    How can I listen for hyperlinksEvents than link in the same page.
    Thanks

    they dont want to see the first report.
    Is there a way in which the Prompts are also display along with the second report?Then create the same prompt on the second report also.
    Cheers
    Nawneet

  • JEditorPane html display problem

    Hello,
    I'm running a JEditorPane inside an Applet for a project im working on. The source included below is an over-simplified version that produces the same results. The problem i'm having is that the html displays in an odd fasion in the JEditorPane.
    Since I cant include a screenshot let me attempt to describe it. Regardless of the FONT face in the html the paragraph displays as you would expect in the JEditorPane until the last line. The last has extra horizontal space separating it from the rest of the paragraph. This seems completely arbitrary. There is nothing in the html code near the line break.
    I've linked this problem to the font face attribute tags. Regardless of the font I choose it displays improperly. Any idea on how to remove this spacing problem in my JEditorPane?
    I'm using NetBeans 3.5.1 and SDK 1.4.2. I've tested this problem in the AppletViewer as well as online in a web browser.
    * CourierTest.java
    * Created on July 24, 2004, 8:28 PM
    import java.awt.Font;
    import java.io.*;
    * @author LD Miller
    public class CourierTest extends javax.swing.JApplet {
    String html;
    /** Initializes the applet CourierTest */
    public void init() {
    initComponents();
    html = "<P class=MsoNormal style=\"MARGIN: 0in 0in 0pt\"><FONT size=3><FONT face=\"Times New Roman\">What is event-driven programming?It is a <I>computer programming</I> paradigm that is different from traditional, sequential programming. In traditional, sequential programming, one could follow the program and plot out exactly the sequence of execution of the program. However, in event-driven programming, it is not possible to plot out exactly the sequence of execution of the program since flow of the execution is determined by the events. Event-driven programming allows a program to interact with users and re-act to user-generated events in a more efficient and effective manner. </FONT></FONT></P>";
    jTextPane1.setContentType("text/html");
    jTextPane1.setText(html);
    /** This method is called from within the init() method to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextPane1 = new javax.swing.JTextPane();
    jScrollPane1.setViewportView(jTextPane1);
    getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
    // Variables declaration - do not modify
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration

    1) I have complex html page (having lot of html controls).
    .when i resize the container, controls gets overlapped.
    shall we avoid this? to my experience JEditorPane deviates from the display of typical browsers when HTML is displayed that contains complex table layouts (tables nested in other tables or non-explicit or non-existent size expressions in tables for instance). I recommend to try and simplify layout complexity as a workaround. Start with a most simple page and increase complexitiy until display gets unsatisfactory.
    2) I used JEditorPane. My html contents are stored in
    text. i called setText()...whether i need to use
    HTMLDocument, HTMLEditorKit etc...to render
    html in better way...I did not understand your second point, what is the question?
    Ulrich

  • JEditorPane/HTML image loading delay

    I am using a JEditorPane to render HTML to a graphics buffer which I then write as an image file. Since HTML loading is asynchronous I wait for the "page" property change event after calling setPage() before using print() to capture the rendered HTML to a graphics buffer. Unfortunately, the "page" property change event is fired after the HTML is loaded but before images referenced by the HTML are rendered. As a result, the image that I capture has little picture icons in place of the graphics. If I sleep for a short time before capturing the image, it works fine. However, sleeping is not an acceptable solution as there is no way to predict how long I will need to sleep because it varies based on system load and complexity of the HTML being rendered. Is there any way to check if an HTML document has completely loaded including all the images? Does anyone have a better way to capture an image of a rendered HTML document that would not have this problem?
    Below is a code snippet that shows what I am trying to do.
    static final JEditorPane p;
    static final Object done;
    static {
        done=new Object();
        p=new JEditorPane();
        p.setSize(1728, 2156);
        p.addPropertyChangeListener("page", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) {
            synchronized(done) {
                done.notifyAll();
    static void capture(File htmlFile) {
        BufferedImage img=new BufferedImage(1728, 2156, BufferedImage.TYPE_BYTE_GRAY);
        synchronized(done) {
            p.setPage(htmlFile.toURL());
            try {
                done.wait();
            } catch(InterruptedException e) {}
    /* without this code images are not rendered
        try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {}
        Graphics g=img.createGraphics();
        g.setColor(Color.white);
        g.fillRect(0, 0, 1728, 2156);
        p.print(g);

    HI Sarnoth,
    I'm trying to do something similar and have used your code, but it doesn't work completely for me. Do you see anything that I'm doing wrong? I am trying to save the HTML page as a JPEG image. This is my code and I'm having problems. Anyone have any ideas? It is dying on the je.encode(bi) line. Also, for some reason, if I uncomment the commented out lines, it hangs. Any ideas on that one too?
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.FileNotFoundException;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import javax.swing.JEditorPane;
    import com.sun.media.jai.codec.ImageCodec;
    import com.sun.media.jai.codec.ImageEncoder;
    import com.sun.media.jai.codec.JPEGEncodeParam;
    public class HTMLPageToImageConverter
         private HTMLPageToImageConverter() {
         static final JEditorPane p;
         static final Object done;
         static {
             done = new Object();
             p = new JEditorPane();
             p.setSize(1728, 2152);
    /*         p.addPropertyChangeListener("page", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) {
                 synchronized(done) {
                     done.notifyAll();
         static void GenerateHTMLBufferedImage(File htmlFile, BufferedImage img) {
             img = new BufferedImage(1728, 2152, BufferedImage.TYPE_BYTE_GRAY);
             synchronized(done) {
                 try {
                      p.setPage(htmlFile.toURL());
                 } catch(IOException e1) {}
    /*             try {
                     done.wait();
                 } catch(InterruptedException e) { System.out.println("GenerateHTMLBufferedImage InterruptedException"); }
             Graphics g = img.createGraphics();
             g.setColor(Color.white);
             g.fillRect(0, 0, 1728, 2152);
             p.print(g);
         public static boolean SaveHTMLFileToJPEG(String htmlFile, String jpegFile) {
              try {
                   BufferedImage bi = null;
                   GenerateHTMLBufferedImage(new File(htmlFile), bi);
                   FileOutputStream fos = new FileOutputStream(jpegFile);
                   JPEGEncodeParam jp = new JPEGEncodeParam();
                   ImageEncoder je = ImageCodec.createImageEncoder("JPEG", fos, jp);
                   je.encode(bi);
                   fos.close();
              } catch(FileNotFoundException fnfe) { System.out.println("SaveHTMLFileToJPEG FileNotFoundException"); }
                catch(IOException ioe) { System.out.println("SaveHTMLFileToJPEG IOException"); }
              return true;
    }Called from other code
    HTMLPageToImageConverter.SaveHTMLFileToJPEG("d:/page1.html", "d:/page1.jpeg");
    ...Thanks in advence,
    --Ed                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • JEditorPane html

    I have a simple JEditorPane set up so that I can view source code and rendered version of an html page. I toggle between rendered and source view by setting the content type:
    setContentType("text/plain") - displays source code
    setContentType("text/html") - dispalys the rendered view
    The problem I have is with offsets. It would be natural to me that the first letter in the rendered view starts at 0 and ends at 1. That's not the case however. In any test page I have, the first letter has offset 3-4. The same things happen inside the text as well. When I count offsets by hand, they are different that what getSelectionStart() and getSelectionEnd() show.
    I'm assuming that there must be some characters that get rendered by JEditorPane but don't get displayed - but quite frankly I have no clue as to why it's happening.
    Any ideas would be appreciated. I wrote a simple algorithm (irrelevant to this post) that uses the rendred view offsets to mark things in the source view, but since my rendered view offsets are screwed up - I'm not able to mark things properly.
    Thanks
    M

    Have you tried displaying the characters between offsets 0-2 ? It could give you an idea of what it concerns...

  • JEditorPane HTML preview

    Hi,
    I've been working on a small class which will render out HTML. There's a few examples on the web, all of which read an HTML file from a URL. JEditorPane works fine for that use, but when I try to specify HTML content as a string the page doesn't get displayed correctly. It's a bit hard to describe but basically if you specify a document as type text/html it tries to generate it's own <html>, <body> tags etc and leaves yours out. If you do happen to specify your own then it just ignores your page content.
    I need to do it that way as the HTML doesn't exist at a URL, only in memory. Does anyone know of a workaround or has anyone else experienced this problem? I'm developing the application using JDK 1.4.0 under Win2k.
    Thanks

    Yeah that's pretty much exactly what I'm doing, although it's pulling the HTML content from the database first.
    Your code outputs this:
    <html>
    <head>
    </head>
    <body>
    <b>Bolloxs</b>
    </body>
    </html>
    As you can see, it's being altered by the application and has had the <head> tags added. In my application it's doing even more, stripping everything inside of the <body> tags.
    I've found the reason though...it doesn't seem to like a meta tag.
    This content:
    String html = new String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>This is my title</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head><body leftmargin=\"0\" topmargin=\"0\"><table width=\"600\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>Page content goes here</td></tr></table></body></html>");
    Outputs:
    <html>
    <head>
    </head>
    <body>
    <p>
    </p>
    </body>
    </html>
    Whilst this content (with the meta line removed):
    String html = new String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>This is my title</title></head><body leftmargin=\"0\" topmargin=\"0\"><table width=\"600\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>Page content goes here</td></tr></table></body></html>");
    Outputs:
    <html>
    <head>
    <title>This is my title </title>
    </head>
    <body leftmargin="0" topmargin="0">
    <table border="0" cellpadding="0" width="600" cellspacing="0">
    <tr>
    <td>
    Page content goes here
    </td>
    </tr>
    </table>
    </body>
    </html>
    Weirdness!?

  • Preferred size of JEditorPane/ HTML page

    Hi,
    I've loaded an HTML page in a JEditorPane. Since I'm using a layout manager with absolute positioning, I need to know the pane's preferred size.But the preferred size I get is just about (6, 6), although it has a big picture in it. I tried validate() first or to add it with (1,1) to have it set up properly (visible etc.) and then resize it afterwards, but it had no effect. Is there a way to get a preferred size of an HTML page?
    Thanks a lot.
    Greets
    Puce
    Note: Using another layout manager is not a option, since this is a very specialized task.

    I could use this as well. I'm tiling JEditorPanes vertically inside a JPanel using BoxLayout. The problem is that I need to limit the width of the panel, so I need to adjust the sizes accordingly. Any suggestions? I'll give another duke...
    Max

  • Caret position in JEditorPane HTML

    Hi everyone,
    I need the position of caret in HTML source on JEditorPane. I
    The value of getCaretPosition() seems not what I wanted. CaretEvent.getDot() gives the same value of getCaretPosition. These methods only gets position on the view.
    Please help! Thanks a lot!

    It's not possible. HTMLParser creates Document's structure (Elements tree) from html text but it has no relation to content.
    Position in source html isn't correct because it may contain unnecesary space between tags or tab chars or \n chars which are ignored.

  • Another JEditorPane HTML performance thread

    I've seen quite a few posts on the forums about people having serious performance issues using JEditorPane or JTextPane with large text. I haven't seen any solutions or work-arounds mentioned though, so I'm just going to throw this one out there again...
    To sum up the issue, it appears that calling setText() on a JEditorPane or JTextPane is terribly inefficient. At the very least when trying to display HTML content. I have an HTML table that I would like to display in my app. It's not unreasonably large (perhaps 1000 small rows), but the setText() method takes anywhere between 30seconds and 1 minute to execute. During this time, the memory footprint of my skyrockets and the second attempt to call setText() will result in a OutOfMemoryException.
    The issue seems to be captured in the following bug:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4203912
    However, this bug was closed for 1.5 release of Java, and I'm still experiencing the issue on the latest JRE currently available (1.5.0_05).
    The performance as it is now is pretty unreasonable. Does anyone have any sort of work-around? I've heard a custom implementation of the Document mentioned in one of the posts, but no code examples were given.
    Does anyone have any further input / help on this issue?
    Thank you.

    JEditorPane and JTextPane can't handle plain String text directly.
    Their M of MVC is Document.
    Try preparing a full fledged Document object and set it to them panes.

  • Named Anchor in JEditorPane HTML

    I am loading an HTML string into a JEditorPane.
    The string has some named anchors (<A NAME="blah">) that reference other locations in the HTML string.
    Because I am loading the HTML string by using JEditorPane.setText, the named anchors do not work. This seems to be a problem when my HyperLinkListener tries to find the target URL.
    Does anyone know how to solve this problem?

    Did you find a solution for this problem in the meantime? I'd like to implement an online help feature in my newest program. I wrote a HTML text with anchors/links and the program loads this text to an JEditorPAne witch HTMLEditorKit by using the EditorPanes 'read' method. But all I got are HyperLinkExceptions from the HyperlinEventListener.
    regards, hgw2

  • JEditorPane HTML load GIF from JAR

    I'm using a jeditorpane to display a html page from a local file system with images in it, will the editor pane load the <img src> tags from a jar file or must the images be on the local file system?

    gifs will have to be on the local drive

  • JEditorPane + html TEXTAREA + WRAP

    Hi, I have a simple program that uses a JEditorPane to create an html TEXTAREA.
    Supposedly the text in the TEXTAREA should be wrapped, and when I add READONLY, the text can�t be deleted. However, the wrapping and readonly don�t work�
    Here is the code:
    import javax.swing.*;
    import java.awt.*;
    public class Main extends JFrame {
        public Main() {
            String abc = "A BIG LONG STRING WHICH SHOULD BE WRAPPED, AND CANNOT BE DELETE...A BIG LONG STRING WHICH SHOULD BE WRAPPED, AND CANNOT BE DELETE...A BIG LONG STRING WHICH SHOULD BE WRAPPED, AND CANNOT BE DELETE...A BIG LONG STRING WHICH SHOULD BE WRAPPED, AND CANNOT BE DELETE...";
            Container ct = getContentPane();
            JEditorPane ep = new JEditorPane();
            ep.setContentType("text/html");
            ep.setText("<body><tr><td class=one width=135>Test Criteria:</b></td><TEXTAREA WRAP=SOFT COLS=20 ROWS=2 READONLY>"
                       + abc + "</TEXTAREA></tr></body>");
            ct.add("Center", ep);
            setSize(400, 300);
            setVisible(true);
        public static void main(String[] args) {
            new Main();
    }Please help me out.
    Thanks.
    Hong Jiang

    As I understand it, JEditorPane's version of HTML is 3.2. Looking in the HTML 3.2 recommendation I don't see "wrap" and "readonly" as acceptable attributes for Textarea.

  • JEditorPane HTML font style changing problems

    I have tried changing the font size using the action:
    StyledEditorKit.FontSizeAction("12", 12)
    but that seems to have problems. When I change it on the editor and write and re-read the change html the font size does not look the same.
    Is there a bug in changing the font size of htmls using the JEditorPane or JTextPane component?
    How/What does the "font-change-bigger" or "font-change-smaller" work with in the HTMLEditorKit? Should I be using these members somehow instead?

    Hello,
    When you use HTMLEditorKit, you can not specify font out size of HTML. For Example, use FONT tag in html to set your font. There are many ways to change font in html. tags like h1, h2 etc..
    O.K.

  • JEditorPane & HTML Parser

    I am creating a Swing application. It's main purpose is to help disabled person to handle the webpages. In the first half of the screen, the webpage is displayed, and in the second half of the screen the url links (those in the first half of the screen) with Big Buttons - to help patient navigate the webpages - are displayed.
    I successfully displayed HTML contents using JEditorPane in the first screen. But I don't know how to handle "Javascript", "Style sheet", which are not supported by JEditorPane. They make the screen ugly.
    One more, it seems that Parser class is a clue for the second screen in getting url links. Once I get url links, displaying in buttons is trivial. But I don't know how to use it. Any good examples?
    I appreciate your help.
    Ghiyoung

    I think the mozilla project has a project for javascript....... Rhino
    www.mozilla.org

Maybe you are looking for

  • IPod does not play well with left speaker

    I have tried several ear buds as well as stereo's for playback with my iPod. The left speaker plays at about 1/2 as loud as the right speaker in all these devices. This has happened with 2 seperate iPods. I've downloaded songs from 2 seperate PC's to

  • Setting IS NULL as viewcriteria

    Hello, A simple question this time. How can one set a viewcriteria to IS NULL. If you want all records where a particular field is empty? Regards Johan

  • Displaying text from XML.

    Hello, I hoping that somone can steer me in the right direction here. Right now I have an application that reads an XML and displays thumbnails of images. A user clicks on the thumbnail and a larger image appears. What I would like to do is, instead

  • Problem in starting oem

    hi every1 i m getting problem while starting oem . please help C:\Users\thiru>set ORACLE_SID=cng1 C:\Users\thiru>emctl start dbconsole Oracle Enterprise Manager 11g Database Control Release 11.1.0.7.0 Copyright (c) 1996, 2008 Oracle Corporation. All

  • Web Service Port Reuse

    JDeveloper 11.1.1.2 We have an application which calls several web services based on JAX-WS. As retrieving the port for each service is costly (typically a half second or more), we have stored the ports in a cache for reuse. This appears to work as l