JEditorPane - setPage

How does one interrupt the loading of a HTML page in setPage of a JEditorPane? Have a situtation where clicking on different URL's should
stop the loading of the previous page...
Thanks
Abraham Khalil

If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
http://homepage1.nifty.com/algafield/sscce.html
Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
http://forum.java.sun.com/help.jspa?sec=formatting

Similar Messages

  • Exceptions with JEditorPane setPage() method (Catching not possible)

    hi all
    if anyone can help me...please help
    I got serious exceptions with the JEditorPane()'s setPage() method
    I have written the try & catch still i could not catch the exception..(those exceptions are not displaying any of my program lines)..setPage() mehod was executed properly and the page was displyed on the editorpane..and then exceptions r coming..
    --------my code--------
    java.net.URL fileurl =LongTask.class.getResource(modifiedfilename);
    editorpane.setPage(fileurl);
    ---------------------exceptions
    java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:393)
    at javax.swing.text.SimpleAttributeSet.addAttribute(SimpleAttributeSet.java:176)
    at javax.swing.text.html.CSS.translateHTMLToCSS(CSS.java:687)
    at javax.swing.text.html.StyleSheet.translateHTMLToCSS(StyleSheet.java:491)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.<init>(StyleSheet.java:2476)
    at javax.swing.text.html.StyleSheet.getViewAttributes(StyleSheet.java:312)
    at javax.swing.text.html.BlockView.getAttributes(BlockView.java:275)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.getResolveParent(StyleSheet.java:2609)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.doGetAttribute(StyleSheet.java:2589)
    at javax.swing.text.html.StyleSheet$ViewAttributeSet.getAttribute(StyleSheet.java:2569)
    at javax.swing.text.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:105)
    at javax.swing.text.html.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:87)
    at javax.swing.text.html.ParagraphView.setParent(ParagraphView.java:60)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.html.BlockView.setParent(BlockView.java:55)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.html.TableView$RowView.replace(TableView.java:1414)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.html.TableView.replace(TableView.java:864)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.html.TableView.setParent(TableView.java:768)
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.BoxView.replace(BoxView.java:164)
    at javax.swing.text.View.updateChildren(View.java:1126)
    at javax.swing.text.View.insertUpdate(View.java:710)
    at javax.swing.text.View.forwardUpdateToView(View.java:1217)
    at javax.swing.text.View.forwardUpdate(View.java:1192)
    at javax.swing.text.BoxView.forwardUpdate(BoxView.java:222)
    at javax.swing.text.View.insertUpdate(View.java:716)
    at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1487)
    at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1726)
    at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:184)
    at javax.swing.text.DefaultStyledDocument.insert(DefaultStyledDocument.java:201)
    at javax.swing.text.html.HTMLDocument.insert(HTMLDocument.java:232)
    at javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(HTMLDocument.java:3254)
    at javax.swing.text.html.HTMLDocument$HTMLReader.addContent(HTMLDocument.java:3196)
    at javax.swing.text.html.HTMLDocument$HTMLReader.blockClose(HTMLDocument.java:3128)
    at javax.swing.text.html.HTMLDocument$HTMLReader$BlockAction.end(HTMLDocument.java:2334)
    at javax.swing.text.html.HTMLDocument$HTMLReader.handleEndTag(HTMLDocument.java:2233)
    at javax.swing.text.html.parser.DocumentParser.handleEndTag(DocumentParser.java:217)
    at javax.swing.text.html.parser.Parser.parse(Parser.java:2072)
    at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java:106)
    at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java:78)
    at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:230)
    at javax.swing.JEditorPane.read(JEditorPane.java:504)
    at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:551)
    please share ideas to solve this problem

    But how can I cause GUI thread to run in my thread
    group? As I suppose GUI thread is started by JVM and
    is something separate from my code - I can get a
    reference to GUI thread but don't know how to
    manipulate or replace it...One alternative is to completely separate the GUI code from your code.
    Your code, which is wrapped in appropriate try/catch blocks, runs on its own thread and does its own processing. When it's done with that processing, it queues the results on the event thread for display. If an exception occurs during your processing, then you queue something that notifies the GUI.
    The simplest way to implement this is to spawn a new thread for each operation. The Runnable that you give to that thread looks like the following:
    public MyOperationClass implements Runnable
        public void run()
            try
                // do your exception-generating code here
                SwingUtilities.invokeLater( new MyGUIUpdateClass(param1, param2));
            catch (Exception e)
                SwingUtilities.invokeLater(new MyExceptionReporter(e));
    }This is only a bare-bones solution (and hasn't been compiled). Since it separates the GUI from actual processing, you'll probably want to display a wait cursor while the processing thread is doing its thing. You'll probably end up implementing a class that implements this pattern. You may also want to create a producer-consumer thread, so that the user won't invoke, say, a dozen different operations at once.
    However, this sort of code is absolutely essential to Swing programming. Most apps do extensive non-GUI processing, such as database queries. If you run such queries in the GUI thread, your GUI will freeze.
    Sun has named this pattern "SwingWorker", although I don't think they've fleshed it out very fully: http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

  • JEditorPane, setPage and EDT

    The setPage(URL url) method for JEditorPane creates a thread and then loads the URL specified. In our software we're using something to check if all work dealing with Swing components is being done on the EDT. The code for this can be found here:
    http://www.clientjava.com/blog/2004/08/20/1093059428000.html
    Anyway, it turns out that the setPage method is not doing its work on the EDT, which seems like a bug since modifying a component off the EDT can lead to problems. Anyone want to shed some light on this topic or tell me if there's anything that can be done about it? Thanks.

    I am using setPage(URL) method to display files selected from a fileTree.
    I am facing a file locking problem, because of the the PageLoader thread spawned by the setPage method.
    The file is locked temporarily some times and prevents other applications to edit it.
    Can anyone help me what should I do to solve this problem?

  • JEditorPane.setPage - detecting that asynchronous image loading is complete

    Hi,
    I'm using a JEditorPane to load and display an html page of a url by using
    setPage(String url) ... and I've added a progress bar to show the user that loading is still occuring.
    Currently i'm detecting that the page has finished loaded by listening for the property change event named "page", like this:
        this.viewEditorPane.addPropertyChangeListener(
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
              if (event.getPropertyName().equals("page")) {
                loadingProgressBar.setIndeterminate(false);
                System.out.println("... finished loading");
          });I appreciate that images are loaded asynchronously.
    So what I'm wondering is how I can detect that all these associated images have also completed loading?
    Thanks ... Dougall

    if you want to load images synchronously you can use like, (i got it from this forum only)
    public class SynchronousHTMLEditorKit extends HTMLEditorKit {
        public SynchronousHTMLEditorKit() {
        public ViewFactory getViewFactory() {
            return new SynchronousImageViewFactory(super.getViewFactory());
        static class SynchronousImageViewFactory implements ViewFactory {
            ViewFactory impl;
            SynchronousImageViewFactory(ViewFactory impl) {
                this.impl = impl;
            public View create(Element elem) {
                View v = impl.create(elem);
                if((v != null) && (v instanceof ImageView)) {
                    ((ImageView)v).setLoadsSynchronously(true);
                return v;
    }

  • JEditorPane.setPage halting other threads

    I'm in the process of creating a program which loads a html-file while I'm running another process at the same time. It seems like setPage halts my process after a short while.
    As an example I slightly altered a piece from a tutorial (http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html)
    to include a button which is counted down with the help of a timer. As you can see, it's halted for about a second or so after a short while.
    Is there any way I can keep the countdown going fluently?
    import javax.swing.*;
    import javax.swing.event.*;
    //import com.inbis.invitt.SimpleBrowser.ButtonDelayer;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    public class Browser extends JFrame implements HyperlinkListener, ActionListener {
    private JButton homeButton;
    private JTextField urlField;
    private JEditorPane htmlPane;
    private String initialURL;
    private Timer timer;
    public Browser(String initialURL) {
    super("Simple Swing Browser");
    this.initialURL = initialURL;
    addWindowListener(new WindowListener() {
    public void windowActivated(WindowEvent e) {
    public void windowClosed(WindowEvent e) {
    System.exit(0);
    public void windowClosing(WindowEvent e) {
    public void windowDeactivated(WindowEvent e) {
    public void windowDeiconified(WindowEvent e) {
    public void windowIconified(WindowEvent e) {
    public void windowOpened(WindowEvent e) {
    JPanel topPanel = new JPanel();
    topPanel.setBackground(Color.lightGray);
    homeButton = new JButton("Home");
    countdownButton(homeButton, 100, 100);
    JLabel urlLabel = new JLabel("URL:");
    urlField = new JTextField(30);
    urlField.setText(initialURL);
    urlField.addActionListener(this);
    topPanel.add(homeButton);
    topPanel.add(urlLabel);
    topPanel.add(urlField);
    getContentPane().add(topPanel, BorderLayout.NORTH);
    try {
    htmlPane = new JEditorPane(initialURL);
    htmlPane.setEditable(false);
    htmlPane.addHyperlinkListener(this);
    JScrollPane scrollPane = new JScrollPane(htmlPane);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    } catch (IOException ioe) {
    warnUser("Can't build HTML pane for " + initialURL + ": " + ioe);
    Dimension screenSize = getToolkit().getScreenSize();
    int width = screenSize.width * 8 / 10;
    int height = screenSize.height * 8 / 10;
    setBounds(width / 8, height / 8, width, height);
    setVisible(true);
    public void actionPerformed(ActionEvent event) {
    String url;
    if (event.getSource() == urlField)
    url = urlField.getText();
    else
    // Clicked "home" button instead of entering URL
    url = initialURL;
    try {
    htmlPane.setPage(new URL(url));
    urlField.setText(url);
    } catch (IOException ioe) {
    warnUser("Can't follow link to " + url + ": " + ioe);
    public void hyperlinkUpdate(HyperlinkEvent event) {
    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    try {
    htmlPane.setPage(event.getURL());
    urlField.setText(event.getURL().toExternalForm());
    } catch (IOException ioe) {
    warnUser("Can't follow link to " + event.getURL().toExternalForm() + ": " + ioe);
    private void warnUser(String message) {
    JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
    public static void main(String[] args) {
    new Browser("http://www.sun.com/");
    public void countdownButton(JButton button, int delayMs, int delaysToPass) {
    ButtonDecreaser buttonDecreaser = new ButtonDecreaser(button, delaysToPass);
    timer = new Timer(delayMs, buttonDecreaser);
    timer.setInitialDelay(0);
    timer.start();
    private class ButtonDecreaser implements ActionListener {
    private int delayAmount;
    private JButton button;
    public ButtonDecreaser(JButton button, int delayAmount) {
    this.delayAmount = delayAmount;
    this.button = button;
    public void actionPerformed(ActionEvent evt) {
    if (delayAmount > 0) {
    button.setText(Integer.toString(delayAmount));
    } else {
    button.setText("Finished");
    timer.stop();
    delayAmount--;
    }

    Thank you very much for the replies so far. :)
    I am currently on a machine with duo-core, but I'd like to make my program compatible with the ones with single as well anyways. I guess I could find a way to have the processes run sequentially instead of parallely, but it would be really neat if I could get it working as I've intended. :)
    As for the code: sorry, my bad. Just tried to edit my original post without any luck. Here it is in proper format:
    import javax.swing.*;
    import javax.swing.event.*;
    //import com.inbis.invitt.SimpleBrowser.ButtonDelayer;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    public class Browser extends JFrame implements HyperlinkListener, ActionListener {
      private JButton homeButton;
      private JTextField urlField;
      private JEditorPane htmlPane;
      private String initialURL;
      private Timer timer;
      public Browser(String initialURL) {
        super("Simple Swing Browser");
        this.initialURL = initialURL;
        addWindowListener(new WindowListener() {
          public void windowActivated(WindowEvent e) {
          public void windowClosed(WindowEvent e) {
            System.exit(0);
          public void windowClosing(WindowEvent e) {
          public void windowDeactivated(WindowEvent e) {
          public void windowDeiconified(WindowEvent e) {
          public void windowIconified(WindowEvent e) {
          public void windowOpened(WindowEvent e) {
        JPanel topPanel = new JPanel();
        topPanel.setBackground(Color.lightGray);
        homeButton = new JButton("Home");
        countdownButton(homeButton, 100, 100);
        JLabel urlLabel = new JLabel("URL:");
        urlField = new JTextField(30);
        urlField.setText(initialURL);
        urlField.addActionListener(this);
        topPanel.add(homeButton);
        topPanel.add(urlLabel);
        topPanel.add(urlField);
        getContentPane().add(topPanel, BorderLayout.NORTH);
        try {
          htmlPane = new JEditorPane(initialURL);
          htmlPane.setEditable(false);
          htmlPane.addHyperlinkListener(this);
          JScrollPane scrollPane = new JScrollPane(htmlPane);
          getContentPane().add(scrollPane, BorderLayout.CENTER);
        } catch (IOException ioe) {
          warnUser("Can't build HTML pane for " + initialURL + ": " + ioe);
        Dimension screenSize = getToolkit().getScreenSize();
        int width = screenSize.width * 8 / 10;
        int height = screenSize.height * 8 / 10;
        setBounds(width / 8, height / 8, width, height);
        setVisible(true);
      public void actionPerformed(ActionEvent event) {
        String url;
        if (event.getSource() == urlField)
          url = urlField.getText();
        else
          // Clicked "home" button instead of entering URL
          url = initialURL;
        try {
          htmlPane.setPage(new URL(url));
          urlField.setText(url);
        } catch (IOException ioe) {
          warnUser("Can't follow link to " + url + ": " + ioe);
      public void hyperlinkUpdate(HyperlinkEvent event) {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
          try {
            htmlPane.setPage(event.getURL());
            urlField.setText(event.getURL().toExternalForm());
          } catch (IOException ioe) {
            warnUser("Can't follow link to " + event.getURL().toExternalForm() + ": " + ioe);
      private void warnUser(String message) {
        JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
      public static void main(String[] args) {
        new Browser("http://www.sun.com/");
      public void countdownButton(JButton button, int delayMs, int delaysToPass) {
        ButtonDecreaser buttonDecreaser = new ButtonDecreaser(button, delaysToPass);
        timer = new Timer(delayMs, buttonDecreaser);
        timer.setInitialDelay(0);
        timer.start();
      private class ButtonDecreaser implements ActionListener {
        private int delayAmount;
        private JButton button;
        public ButtonDecreaser(JButton button, int delayAmount) {
          this.delayAmount = delayAmount;
          this.button = button;
        public void actionPerformed(ActionEvent evt) {
          if (delayAmount > 0) {
            button.setText(Integer.toString(delayAmount));
          } else {
            button.setText("Finished");
            timer.stop();
          delayAmount--;
    }

  • JEditorPane.setPage(URL url), then I want to clean up HTML, how?

    According to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4695909
    the problem with the inconsistent ArrayIndexOutOfBoundsException that
    I have been getting whenever I would go to a particular URL to put
    into JEditorPane using setPage() - this may also be due to JEditorPane
    containing HTML which contains a <META> tag and/or <!-- comment tag --
    . I created a class SimpleHTMLRenderableEditorPane which extendsJEditorPane, based upon code I found in the aformentioned bug link
    which should auto-strip out "bad tags":
    * SimpleHTMLRenderableEditorPane.java
    * Created on March 13, 2007, 3:39 PM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package com.ppowell.tools.ObjectTools.SwingTools;
    import javax.swing.JEditorPane;
    * A safer version of {@link javax.swing.JEditorPane}
    * @author Phil Powell
    * @version JDK 1.6.0
    public class SimpleHTMLRenderableEditorPane extends JEditorPane {
        //--------------------------- --* CONSTRUCTORS *--
        // <editor-fold defaultstate="collapsed" desc=" Constructors
    ">
        /** Creates a new instance of SimpleHTMLRenderableEditorPane */
        public SimpleHTMLRenderableEditorPane() {
            super();
        // </editor-fold>
        //----------------------- --* GETTER/SETTER METHODS *--
        // <editor-fold defaultstate="collapsed" desc=" Getter/Setter
    Methods ">
         * Overloaded to fix HTML rendering bug Bug ID: 4695909.
         * @param text
        public void setText(String text) {
            // Workaround for bug Bug ID: 4695909 in java 1.4
            // JEditorPane does not handle the META tag in the html HEAD
            if (isJava14() && "text/
    html".equalsIgnoreCase(getContentType())) {
                text = stripMetaTag(text);
            super.setText(text);
        // </editor-fold>
        //--------------------------- --* OTHER METHODS *--
        // <editor-fold defaultstate="collapsed" desc=" Methods ">
         * Clean HTML to remove things like <script>, <style>, <object>,
    <embed>, and <!-- -->
         * Based upon <a href="http://bugs.sun.com/bugdatabase/view_bug.do?
    bug_id=4695909">bug report</a>
        public void cleanHTML() {
            try {
                String html = getText();
                if (html != null && !html.equals("")) {
                    String[] patternArray = {
                        "<script[^>]*>[^<]*(</script>)?",
                        "<style[^>]*>[^<]*(</style>)?>",
                        "<object[^>]*>[^<]*(</object>)?>",
                        "<embed[^>]*>[^<]*(</embed>)?>",
                        "<!\\-\\-.*\\-\\->"
                    for (int i = 0; i < patternArray.length; i++) {
                        html = html.replaceAll(patternArray, "");
    setText(html);
    } catch (Exception e) {} // DO NOTHING
    * Determine if java version is 1.4.
    * @return true if java version is 1.4.x....
    private boolean isJava14() {
    String version = System.getProperty("java.version");
    return version.startsWith("1.4");
    * Workaround for Bug ID: 4695909 in java 1.4, fixed in 1.5
    * JEditorPane fails to display HTML BODY when META
    * tag included in HEAD section.
    * <html>
    * <head>
    * <META http-equiv="Content-Type" content="text/html;
    charset=UTF-8">
    * </head>
    * <body>
    * @param text html to strip.
    * @return same HTML text w/o the META tag.
    private String stripMetaTag(String text) {
    // String used for searching, comparison and indexing
    String textUpperCase = text.toUpperCase();
    int indexHead = textUpperCase.indexOf("<META ");
    int indexMeta = textUpperCase.indexOf("<META ");
    int indexBody = textUpperCase.indexOf("<BODY ");
    // Not found or meta not inside the head nothing to strip...
    if (indexMeta == -1 || indexMeta > indexHead && indexMeta <
    indexBody) {
    return text;
    // Find end of meta tag text.
    int indexHeadEnd = textUpperCase.indexOf(">", indexMeta);
    // Strip meta tag text
    return text.substring(0, indexMeta-1) +
    text.substring(indexHeadEnd+1);
    // </editor-fold>
    However, upon running the following line:
    SimpleBrowser.this.browser.cleanHTML();I spawn the following exception:
    Exception in thread "Thread-2" java.lang.RuntimeException: Must insert
    new content into body element-
            at javax.swing.text.html.HTMLDocument
    $HTMLReader.generateEndsSpecsForMidInsert(HTMLDocument.java:1961)
            at javax.swing.text.html.HTMLDocument
    $HTMLReader.<init>(HTMLDocument.java:1908)
            at javax.swing.text.html.HTMLDocument
    $HTMLReader.<init>(HTMLDocument.java:1782)
            at javax.swing.text.html.HTMLDocument
    $HTMLReader.<init>(HTMLDocument.java:1777)
            at
    javax.swing.text.html.HTMLDocument.getReader(HTMLDocument.java:137)
            at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:
    228)
            at javax.swing.JEditorPane.read(JEditorPane.java:556)
            at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:
    647)What should I do at this point?
    Thanks
    Phil

    Transfer all purchases from the iPad to iTunes on your computer, backup the iPad and then sync one last time.
    Then go to Settings>General>Reset>Erase all content and Settings to completely erase the iPad.
    Connect the new iPad to your computer and launch iTunes, restore from the backup of the old iPad and then sync with iTunes. You should be prompted to restore from the backup when you connect the new iPad to your computer's iTunes, but you can select it on your own as well.
    Transfer purchases.
    http://support.apple.com/kb/HT1848
    How to backup
    http://support.apple.com/kb/HT1766

  • JEditorPane setpage() problems

    Hi all!!
    I am developing a SWING application wich consists of a JFrame that contains a splitpane with a JTree on the left side and a JPanel with a cardlayout on the right one.
    Once the user navigates through the tree on the left different cards get loaded on the right panel.
    My problem is that when I show the card where a JEditorPane is located and use the setPage(url) to modify the document to be shown nothing happens, meaning that it doesn�t change the document that is displayed (the one URL that I passed on creating the JEditorPane). I mean, the card gets loaded, and I have confirmed that the URL that I pass exists and I pass different ones as well, but nothing seems to happen and the document remains the same.
    Please, can you give me any hints of why this is happening? Can I repaint the card or something??
    Is there any relationship between the CardLayout and the unability to setPage the JEditorPane.
    Please Help!!
    Here is the code:

    I've had this Problem when I was building a HTML-Editor-Applet.
    The Problem was, that there was a Style-Attribute like e.g. text-decoration:underlined. If I removed the underlined style the Attribut was text-decoration:none, but the getText() method just cared about the Style with the name text-decoration to handle this Element as underlined. I had to build my own getText() method by examing all the Elemntes from the Document and set the html-Tags for the style-attributes.
    J&ouml;rn

  • JEditorPane.setPage() final  phase takes a while!!!

    Hi Java users,
    I'm displaying a document on a JEditorPane. I am using a SwingWorker to launch a thread that will accomplish the document load. However, there is a point when the SwingWorker has already finished his job (I now this since the finished() code has been executed), and it takes a few seconds more to display the document during which period I don't have any means to inform the user that all is in order and tell him to be patient. The JEditorPane shrinks to a tiny little white rectangle (almost a point) then -few sec. later- the document is shown. How can this issue be solved???
    Also, hard question, in spite of using the SwingWorker sometimes (withou any systematical pattern, randomly) the GUI "freezes". How is this possible?
    Thanks for your help in advance,
    Balint

    setPage already launches a separate thread to load
    the page; hence the method may return before the job
    is actually done: that terminates the SwingWorker
    construct. You control that via set/get
    getAsynchronousLoadPriority, which in turn use the
    AbstractDocument.AsyncLoadPriority priority: only if it
    not set (<0) the document will load synchronously.
    The GUI may freeze because it has less priority than
    needed. I use the following function   private static void lowerThreadPriority()
          Thread t = Thread.currentThread();
          int p = t.getPriority();
          if (p > Thread.MIN_PRIORITY)
             t.setPriority(p - 1);
       } to lower the priority of a SwingWorker, as they
    start with the same priority of the GUI.
    The GUI thread needs to gain read access to the document
    to update the display as new data is being loaded. So,
    it is important that the function that loads the doc
    does not lock it for writing for the whole process, if
    you want data to become visible before loading ends.

  • Loading JEditorPane from an XML file parsed by

    an XSL translator.
    the JEditorPane setPage needs a URL, I'm wondering if there is anyway way to have the XSL tool write directly to the JEditorPane?

    If the XSL translator is producing HTML, and it can be run at the command line and send its output to stdout (as many of them can), then there's an approach to a solution.
    JEditorPane has a read() method that takes an InputStream as a parameter. You could use Runtime.getRuntime().exec() to run the XSL translator, then use getInputStream() from the resulting Process object to capture its output, and give that InputStream to JEditorPane.read().
    That's an outline of what I would try. Runtime.exec() is a notoriously irritating thing to get working, so it might fail, but you could give it a try.

  • Problem using Proxie server with Authentication & JEditorPane

    Hello
    I don't know if anyone has done this and if someone has I would really appreciate any help you could give me. I need to display a web page in a JEditorPane but the web page is accessed through a proxie server that uses authentication. I have tried using the setPage with username:[email protected] URL format for authentication but it doesn't work.
    JEditorPane.setPage(new URL(urlStr))
    this gives me an exception. The following is the exception message and printStackTrace
    error:Server returned HTTP response code: 401 for URL: (Url I am trying to access)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:709)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:238)
    at javax.swing.JEditorPane.getStream(JEditorPane.java:674)
    at javax.swing.JEditorPane.setPage(JEditorPane.java:392)
    at com.UrlChecker.panels.HTML.EditorPane._$2863(EditorPane.java:184)
    at com.UrlChecker.panels.HTML.EditorPane.changeUrls(EditorPane.java:321)
    Thank you for any help you can give me.

    Steve,
    The URLs that I am using are internal. A similar type login page is the Oracle Metalink
    http://metalink.oracle.com/metalink/plsql/ml2_gui.startup
    I will try to find another webstie that you can test. Be back shortly
    thanks

  • URGENT: JEditorPane (a Java Browser) displaying HTML form

    Hi,
    I am using JEditorPane to display the wb pages but geeting problem as
    I don't get any kind of event when I click on the HTML form SUBMIT button though it does work but didn't allow me to get the URL of the new page that I got after hitting this SUBMIT button..
    I searched the whole net and it seems to me that lot of people got this problem...
    As I need this for my project please HELP me as soon as possible.

    This may be too late for you (hopefully not), but I had the same problem a little while ago and just figured out how to fix it. Basically, you need to examine the Element structure of the html yourself and manually handle the form, as far as I can tell. There are several ways to display a URL in a JEditorPane, but the most straight-forward (JEditorPane.setPage(URL url)) doesn't actually store the Element structure anywhere accessible. Here's the code to load the page:
    JEditorPane contents;
    HTMLEditorKit kit = new HTMLEditorKit();
    HTMLDocument htmlDoc = new HTMLDocument();
    contents.setEditorKit(kit);
    contents.setDocument(htmlDoc);
    URL url = new URL("http://blahblahblah.com");
    contents.read(url.openStream(), htmlDoc);Now that you have the page loaded correctly, you can access to the Elements within. You can use htmlDoc.getDefaultRootElement() to get the root and then iterate recursively through all the child Elements, checking out the Attributes of each. This will look for the submit button and add a listener to it for you:
    private void parseElements(Element elem) {
        AttributeSet atts = elem.getAttributes();
        //If this is the submit button, add a listener:
             Object model = atts.getAttribute(StyleConstants.ModelAttribute);
             Object type = atts.getAttribute(HTML.Attribute.TYPE);
             if ((type != null) && (type.equals("submit"))) {
                 DefaultButtonModel btn = (DefaultButtonModel) model;
                 btn.addActionListener(new ActionListener() {
                     public void actionPerformed(ActionEvent event) {
                         System.out.println("Yay!");
        //Recurse
        for (int i = 0; i < elem.getElementCount(); i++)
             parseElements(elem.getElement(i));
    }Of course, printing out "Yay!" is not really very helpful. When you're parsing through the Elements, check for the attribute StyleContsants.ModelAttribute. If that exists, you can cast it to the correct type of Model (see the documentation for HTMLDocument.HTMLReader.FormAction for information about what types of models to expect from what types of HTML elements) and store it until the "submit" button is pressed. Then all you have to do is get all the data from the models, format it and submit it to the action URL in either a "get" or a "post." The action URL is stored, in Java 1.3, in the HTML.Tag.Form attribute of one of the Elements (I don't remember which one). Getting that attribute returns a SimpleAttributeSet, and you get the HTML.Attribute.Action out of that. In Java 1.4 it's easier to find, you just have to look for the HTML.Attribure.Action attribute in one of the Elements.
    Why isn't this all automatically done for you? I don't know. Good luck.
    -Nathan

  • How to speep up opening html page in JEditorPane

    When i call jeditorPane.setPage( URL u ) it takes about 20 seconds to show page in my JEditoPane. Could you write how to speed up loading html page. My page has 30 page. Thanks!

    When i call jeditorPane.setPage( URL u ) it takes about 20 seconds to show page in my JEditoPane. Could you write how to speed up loading html page. My page has 30 page. Thanks!

  • Displaying a webpage in a JEditorPane from a JApplet

    Hi.
    I am trying to display a webpage in a JEditorPane from an a JApplet.
    I've tried.
    try {
            URL url = new URL("http://www.yahoo.com");
            jEditorPane1.setPage(url);
            } catch(Exception e) {e.printStackTrace();}But I got an AccessControlException:
    java.lang.RuntimeException: java.security.AccessControlException: access denied (java.net.SocketPermission www.yahoo.com:80 connect,resolve)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
         at java.net.HttpURLConnection.getResponseCode(Unknown Source)
         at javax.swing.JEditorPane.getStream(Unknown Source)
         at javax.swing.JEditorPane.setPage(Unknown Source)
         at DisplayDialog.<init>(DisplayDialog.java:21)
         at TestFrame.jButton2ActionPerformed(TestFrame.java:477)
         at TestFrame.access$200(TestFrame.java:15)
         at TestFrame$3.actionPerformed(TestFrame.java:432)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission www.yahoo.com:80 connect,resolve)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkConnect(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.<init>(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         ... 31 more
    I seem to recall something about an applet only being allowed to access pages on the same server. Is there any way to display an external webpage in a JEditorPane? Thanks.

    Unless you sign the applet's jar, you can only fetch urls from the same host as the applet was downloaded from. Part of the sandbox security restrictions.
    So go look up jarsigner for details.

  • JEditorPane doesn't redraw if URL same

    I'm generating HTML by styling an XML file using XSLT to a temp HTML file and using jEditorPane.setPage( tempURL ) to display it. No problem there. However if I regenerate new content to the same file name and ask JEditorPane to draw this then it says to itself "this is the same URL I put up before so I'm not going to redraw it" - even though the actual contents of the file have changed.
    I don't want to have to use a different temp file for each run, or even to flop back and forth between 2 temp files (which I believe would work).
    How do I get JEditorPane to redraw if the file name is the same as the previous call?

    Here's my solution - I replace the HTMLEditorKit if it's not the first pass through. I found that the EditorKit is an instance of HTMLEditorKit for every pass except the first (which doesn't have a problem).
    EditorKit ek = displayJEditorPane.getEditorKit();
    if( ek instanceof HTMLEditorKit ) {
         // Needs to be replaced
         HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
         displayJEditorPane.setEditorKit( htmlEditorKit );
    // Display the HTML document
    displayJEditorPane.setPage( resultURL );I'll spread my Duke Dollars around to everyone who offered a suggestion later today if I don't hear of a better solution.
    Thanks.

  • JEditorPane Initialization problem

    Hi All,
    I am getting the following error if i am trying to initialize JEditorPane as below,
    JEditorPane j_msgPanel=new JEditorPane("file:\\\\C:\\msgCreator\\blank.html");
    java.net.ConnectException: Operation timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.NetworkClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.<init>(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(Unknown Sour
    ce)
    at javax.swing.JEditorPane.getStream(Unknown Source)
    at javax.swing.JEditorPane.setPage(Unknown Source)
    at javax.swing.JEditorPane.<init>(Unknown Source)
    at adx.msg.TabbedMsgCreator.jbInit(TabbedMsgCreator.java:104)
    at adx.msg.TabbedMsgCreator.<init>(TabbedMsgCreator.java:89)
    at adx.msg.Login.submitClicked(Login.java:167)
    at adx.msg.Login.access$000(Login.java:18)
    at adx.msg.Login$2.actionPerformed(Login.java:77)
    at javax.swing.JTextField.fireActionPerformed(Unknown Source)
    at javax.swing.JTextField.postActionEvent(Unknown Source)
    at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processKeyEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    For more information, i am using
    java version "1.3.1"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
    Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
    I have no idea why it is going for ftp connection :( when the file referenced is a local file.
    Thanks in Advance.

    Sorry i forgot to add that this works fine with jdk 1.4.1 version

Maybe you are looking for

  • Can I set a default folder in Acrobat?

    Most of my PDF files are in one location.  I would like to be able to set that location as the default folder in which Acrobat will look when I want to open a file.

  • VPRS Cost Determination in Billing document

    Dear Friends,   We are facing an issue in cost determination,  we are creating intercompany billing between the companies.  As part of price determination, we determine standard cost from the material master for price calculation.  Addtionally, we ar

  • Scheduling parameters are not defined for production orders

    Hi All,          when i convert the planned order to production order  i got this massage popup coming  Scheduling parameters are not defined for production orders . please let me know this .

  • Message traceability in PI - File Adapter

    Hi Experts, I have a Idoc to FTP scenario. Idocs are sent from SAP R/3 to PI where they are converted to file format and saved. Another communication channel reads these files one by one and sends them to an FTP folder. Now my question is, how will I

  • OnDemand after Source Clocked give "internal error status -88700"

    Hi, I am using Analog Input and Counter Input simultaneously with a shared internal clock source on the NI PCIe-6363 I'm running on WinXP, with NIDAQmx Driver 9.1.1f0 I start off by doing some OnDemand acquisitions and it all works. Then I configure