Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6502558

AbstractDocument fires event not on Event Dispatch Thread


    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:


      All Swing listeners must be notified on Event Dispatch Thread
      please see http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html

      "Swing components will generally not comply with the single-thread rule unless all their events are sent and received on the event-dispatch thread. For example, property-change events should be sent on the event-dispatch thread, and model-change events should be received on the event-dispatch thread."

      But following example shows that document listener notifications clearly break this rule
      (don't forget to set proxy settings properly)

      Current behaviour:
      DocumentListener notifications are sent from the wrong thread

      Expected behaviour:
      DocumentListener notifications must be sent from Event Dispatch Thread only

      import javax.swing.*;
      import javax.swing.event.DocumentEvent;
      import javax.swing.event.DocumentListener;
      import javax.swing.text.Document;
      import javax.swing.text.html.HTMLEditorKit;
      import java.awt.*;
      import java.io.IOException;
      import java.net.URL;
      import java.util.Properties;

      /** @author JohnM */

      public class EditorPaneEDTViolation extends JFrame{
          static JEditorPane msgArea;

          public EditorPaneEDTViolation() {
              setTitle("EDT Violations R Us");
              setLayout(new BorderLayout());

              msgArea = new JEditorPane();
              JPanel p = new JPanel();
              p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
              add(p, BorderLayout.CENTER);

              setBounds(100, 100, 800, 600);

          public static void main(String[] args) {

              Properties systemproperties = System.getProperties();
                                   "yourcache");// http proxy server
                                   "80"); // http port #


              EventQueue.invokeLater(new Runnable(){
                  public void run(){
                      final EditorPaneEDTViolation epv = new EditorPaneEDTViolation();
                      try {
                          msgArea.setEditorKit(new HTMLEditorKit() {
                              public Document createDefaultDocument() {
                                  Document doc = super.createDefaultDocument();
                                  doc.addDocumentListener(new DocumentListener() {
                                      public void insertUpdate(DocumentEvent e) {
                                          if (!SwingUtilities.isEventDispatchThread()) {
                                              System.out.println("Error !!!");

                                      public void removeUpdate(DocumentEvent e) {
                                          if (!SwingUtilities.isEventDispatchThread()) {
                                              System.out.println("Error !!!");

                                      public void changedUpdate(DocumentEvent e) {
                                          if (!SwingUtilities.isEventDispatchThread()) {
                                              System.out.println("Error !!!");
                                  return doc;
                          msgArea.setPage(new URL("http://www.google.com"));

                      } catch (IOException ex) {




            • Assignee:
              peterz Peter Zhelezniakov (Inactive)
              alexp Alexander Potochkin (Inactive)
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: