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?

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

    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

  • 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 - Links and Mailtos...

    Hi everyone,
    For a while now, I have been trying to figure out how to get hyperlinks working in a JEditorPane. I realize I could make it uneditable and all that, but I need two things above and beyond:
    1) I need the link you clicked to open in your default web browser.
    2) I need "mailto" links to open a new e-mail in your default e-mail client.
    I have no idea where to find code for (1) and (2)... I have searched high and low and can't find anything useful, especially for (2).
    I would be grateful for any help.
    Thank you,
    Wojciech

    Hello Jesper:
    I do have mye links as a componet and it is easy to make any changes, but the links still add size to every page, which is what I don't want. I might have to redo my website using frames because I think this is the only way to have the links load once. (is this right?).
    I was hoping to not have to redo my entire site ... as it will be a lot of work and I was hoping there would beanother option.
    Thank you for your help.
    Brenda

  • Swing, Animation and EDT

    I am developing an application where I have a JPanel and custom components (by this I mean I am extending JLabel). These custom components are added to the JPanel and I would like them to animate when they receive a command.
    As each component may receive the same messages and therefore may wish to animate at the same time I have created Runnable objects and these are added to the EventQueue when required. Each custom component is implemented as follows:
    public class CustomRobot extends JLabel implements CANListener {
        //variable declarations and attributes
        //overriding paincomponent
       public void paintComponent(Graphics g){
           super.paintComponent(g);
           2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                         RenderingHints.VALUE_ANTIALIAS_ON);  
           g2.rotate(rotationDegree, getWidth()/2-5, getHeight()/2);
           g2.draw(robInUpper);
           g2.draw(robInGripperR);
           g2.draw(robInGripperL);
           g2.draw(robotPlatform);
        //This method is fired when a message is received by the CANListener
        //Similar to actionPerformed() from ActionListener
        public void onMessage(Message message) {
            try {
             if (message instanceof TextMessage) {
             TextMessage tm = (TextMessage) message;
                if (tm.getText().startsWith("0x0a")){
              EventQueue.invokeLater(pickup);
            } catch (Exception ex) {
              System.err.println(ex.getMessage());
           Runnable pickup = new Runnable(){
             public void run(){
              while(Math.toDegrees(rotationDegree) < 90){
                   rotationDegree += rotationTheta;
                   System.out.println(Math.toDegrees(rotationDegree));
                    try { Thread.sleep(100); } catch (Exception e) { 
                                        System.out.println("Error"); }
                    repaint();
    The problem is that the component will only repaint when it gets to 90 degrees, it does not animate. Am I going about this totally wrong? I have the feeling that maybe it is because I am trying to animate the component from within itself rather than in a different class.
    Any help would be greatly appreciated.
    Thanks!

    Am I going about this totally wrong?You are telling the EDT to sleep. If it sleeps then it can't receive events or repaint the GUI. Using a separate Thread is one solution for removing long running code from the EDT. And telling another Thread to sleep will not affect the EDT.
    However if you want animation then use a [url http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html]Swing Timer. The timer simply fires an event every "x" ms and you can then tell your component to repaint itself.

  • JEditorPane, setText, and redraw problems.

    This code was borrowed from another post on the forum. The aim is to append lines of text onto the bottom of the editor pane.
        JEditorPane messagePane = new JEditorPane("text/html", "");
        String text = messagePane.getText();
        text = text.substring(text.indexOf("<body>") + 6, text.indexOf("</body>"));
        text = text + "<br>" + message;
        messagePane.setText(text);It works, but the whole editor pane flashes when setText is called.
    Is there anything I can do to prevent this? I've tried setDoubleBuffered(true) but that doesn't seem to work.
    There are a whole lot of methods on HTMLDocument like insertBeforeEnd which should allow me to insert content before the end body tag, but they don't work anyway.

    I've encoutered this problem and I use the following to replace the call to setText, actually this call causes the flicker effect you experience (for some obscure reason involving callbacks and property change)
            String myString = "<html><body>Sample text, put yours here</body></html>";
            EditorKit kit = this.messagePane.getEditorKit();
            Document newDocument = kit.createDefaultDocument();
            StringReader reader = new StringReader(myString);
            try
                kit.read(reader, newDocument, 0);
                this.messagePane.setDocument(newDocument);
            catch (Exception e)
                this.messagePane.setText("Error " + e);
            }Et voil�, no more flickering !

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

  • JEditorPane, HTML, and image

    I need help to display images into an JEditorPane that show a String rapresent the an HTML page.
    can anyone help me?

    I'm making more investigation in this issue and what I can see is that jEditorPane doesn't care about the <div style="width:348px; ">
    that I put in the html code, can anyone give me and idea?
    thanks for reading

  • JEditorPane ,MyHTMLEditorKit and HTML

    hi java folks
    i want to display html in JEditorPane that is set to the
    MyHTMLEditorKit , the problem is when ever i encounter
    <body background= "..."> tag i should display background image that is created using Toolkit.getDefaultToolkit().createImage(imagebytes);
    MyHTMLEditorKit extends HTMLEditorKit {
    MyHTMLFactory extends HTMLEditorKit.HTMLFactory{
    public View create(Element elem) {
    if ( tag == HTML.Tag.SRC)
    return new MyImageView(elem);
    else
    return super.create(elem);
    MyImageView is nothing but the source code of ImageView except the function getImage() is replaced
    please help me by telling the classes and methods that i should override
    thanks in advance
    bye
    krishna

    There's an article on JavaWorld that explains how to use this technique. It's here:
    http://www.javaworld.com/javaworld/javatips/jw-javatip109.html
    Cheers,
    Howard Kistler

  • [SOLVED] Timezones UTC and EDT all mixed up

    I have the following settings in rc.conf:
    HARDWARECLOCK="localtime"
    TIMEZONE="Eastern US"
    The clock in the lower right panel does indeed indicate the time in EDT.  However, as a screensaver I use the big analog clock and I also put an analog clock in the Arch login window.  Both of these clocks show the time in UTC, i.e. 4 hours ahead of EDT.  What's worse, the time stamping of all saved files, logs, etc. is also in UTC, and the "date" command shows time in UTC.  I believe this is the result of my at one time having run
    # date -u
    How do I reverse this so that all clocks and timestamping are synchronized to EDT?
    Last edited by RobF (2007-04-23 19:49:12)

    "hwclock" gives the time in UTC.
    After I ran hwclock, I went into the BIOS.  The date and time in the BIOS was set for UTC time.  I reset that to the EDT time and then did a warm reboot.  That didn't make any difference in Arch.
    I do dualboot into Windows XP.  The time there is correct (i.e. shows it in EDT), both in the taskbar and when running "time" from the DOS CLI.
    After resetting the BIOS and checking these things in Windows, I did a cold reboot into Arch.  Now, in Arch, the login clock and the screensaver clock show the correct time (in EDT).  The "date" as well as the "hwclock" command also give the correct time (in EDT) but they say that it's UTC!  However, the clock in the bottom panel now runs 4 hrs. behind.  When I right-click on this clock and choose "Adjust Date & Time", the "Configure - KDE Control Module" window that comes up shows the correct time (in EDT) and the entry "New York - America/US - Eastern Time" in the "change timezone" box is highlighted but underneath that box it says "Current local timezone: America/New York (UTC)".
    When I highlight another entry in this change timezone box and then go back to the entry "New York - America/US - Eastern Time" and click on Apply, the clock in that box resets to 4 hours earlier.  When I then redial the clock to the correct EDT time (with the up and down buttons) and hit <Enter>, it shows the correct EDT time and the line underneath the change timezone box now reads "Current local timezone: America/New York (EDT)".  Also, the clock in the bottom panel now shows the correct EDT time.
    When I now run the "date" command, it gives the time 4 hours ahead and says it's UTC (which is correct).  When I save a file, it's timestamped to this UTC time.  But I don't want to have all files and logs timestamped to UTC!!  hwclock now gives the correct EDT time but says that it's UTC!
    It gets worse.  After making all of these changes, I did a cold reboot into Arch.  Now the login clock and screensaver clock are back again to running 4 hrs. ahead (i.e. giving UTC time), and similarly the date and hwclock commands again give the time 4 hrs. ahead and say it's UTC (which is correct).  And the KDE time & date adjust box again says "Current local timezone: America/New York (UTC)".  I.e. any adjustment I make through the KDE Control Center Module doesn't survive a reboot.  It looks as though the "date -u" command overrides everything.  If only I could reset the "date" command to printing EDT time (which I believe is the default that was used before I ran the date  -u command)!  I've looked everywhere but haven't found a way to undo this -u switch and return to the default.
    FWIW, I should say that I installed OpenNTPD, and I'm now running the ntp daemon (ntpd) on startup.  I did this after I became aware of this time readout problem but running ntp didn't change anything.
    Needless to say, I'm rather confused.

  • 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 PageLoader thread causing exceptions, not on EDT

    Hello,
    I have a swing GUI that creates a JEditorPane component and loads up an HTML file using the setPage() method to finally display it. I'm occaisionally getting NullPointerExceptions and ArrayIndexOutOfBoundsExceptions when running the GUI. It is apparent that the JEditor pane spawns a page loading process to load up the HTML. When the loading completes, this page loading thread signals the swing JEditorPane component to update its display. Because the signalling is being done from the pageloader thread and not from the EDT it seems to be creating race conditions and therefore the exceptions.
    An example of the typical stacktrace thrown is:
    Exception in thread "Thread-6" java.lang.NullPointerException
    at javax.swing.text.CompositeView.replace(CompositeView.java:200)
    at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
    at javax.swing.text.FlowView$LogicalView.loadChildren(FlowView.java:684)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.FlowView.loadChildren(FlowView.java:122)
    at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
    at javax.swing.text.FlowView.setParent(FlowView.java:272)
    at javax.swing.text.html.ParagraphView.setParent(ParagraphView.java:58)
    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:1457)
    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:896)
    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:800)
    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.html.HTMLEditorKit$HTMLFactory$BodyBlockView.setParent(HTMLEditorKit.java:1277)
    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:1095)
    at javax.swing.text.View.insertUpdate(View.java:679)
    at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1590)
    at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1849)
    at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:185)
    at javax.swing.text.DefaultStyledDocument.create(DefaultStyledDocument.java:145)
    at javax.swing.text.html.HTMLDocument.create(HTMLDocument.java:281)
    at javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(HTMLDocument.java:3323)
    at javax.swing.text.html.HTMLDocument$HTMLReader.flush(HTMLDocument.java:2127)
    at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:231)
    at javax.swing.JEditorPane.read(JEditorPane.java:557)
    at javax.swing.JEditorPane.read(JEditorPane.java:585)
    at javax.swing.JEditorPane$PageLoader.run(JEditorPane.java:648) As can be seen from the stack trace, the javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:185) line is called from the PageLoader.run thread which attempts to manipulate the swing component.
    I haven't prepared a small compact test case for this yet as it is a race condition and only occurs under certain timings. The GUI on my machine throws these exceptions on almost every second run but far less frequently on another test machine.
    I'm using Java 6 u 13 b 3 in linux ubuntu Jaunty.
    Is there a way to load the page synchronously or to correctly load the page without causing these exceptions?
    Thanks,
    Mark
    Edited by: Mark_Silberbauer on Jun 9, 2009 11:30 AM

    I would try to create a HTMLDocument instance and read content there by the kit you use. When the document's filling is finished just call editorPane.setDocument() in EDT.
    Regards,
    Stas

Maybe you are looking for

  • Very Slow VPN

    I have a pretty basic server setup. The same setup I've done many times before (although all the others have been on 10.5). Basically the server is also the router. VPN uses the high end of the IP range, DHCP uses the middle. The firewall is set up t

  • Error on auto execute of job

    Hii, I am using Oracle 11g version 11.2.0.2.0 From last few days i am getting the error ORA-12012: error on auto execute of job 179297 ORA-01403: no data found ORA-06512: at line 1 in my alert log. The trace file details are : Trace file C:\APP\MANAG

  • How do I delete a huge number of duplicate albums from my itunes for mac library?

    I have a huge itunes music library, over 900 GB, and as it turns out I have a huge number of duplicate albums.  Is there a way to automatically get rid of the duplicate albums so I am left with only one of each?  If not, what is the best way to ident

  • Create service entry sheet button doesn't respond

    Hi, We are using service entry sheets through the portal. I am clicking on the row with the PO for which I'd like to create Service entry sheet and then I am trying to click on the button 'Create service entry sheet'. What is strange that after click

  • Excise paid to capture in sap

    Hi expert I have paid some excise duty from  bank to government . i want to know the process , one should must carry out in SAP with Tcode Regard Nabil