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

Component.processKeyEvent is not called by event dispatch thread

XMLWordPrintable

    • b28
    • sparc
    • solaris_2.6

      Name: dsR10051 Date: 10/17/2000



      The method
      protected void java.awt.Component.processKeyEvent(KeyEvent e)
      is not called by event dispatch thread even if a KeyListener
      object is registered via addKeyListener
      (See JavaDoc for Component.processKeyEvent).

      Here is a minimized test:
      import java.awt.*;
      import java.awt.event.*;

      public class ComponentTest5 {
          public static void main (String[] args) {
              EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
              ChildComponent chcomponent = new ChildComponent();
              KeyEvent e = new KeyEvent(chcomponent, KeyEvent.KEY_RELEASED, (long)0, 0, KeyEvent.VK_UNDEFINED);
              DummyKeyListener cl = new DummyKeyListener();
              chcomponent.addKeyListener(cl);

              eq.postEvent(e);
              synchronized (chcomponent) {
                  while(!chcomponent.keyEventProcessed) {
                      try {
                          System.out.println("Waiting");
                          System.out.flush();

                          chcomponent.wait();

                          System.out.println("Waiting");
                          System.out.flush();
                      } catch (InterruptedException ie) {
                          ie.printStackTrace();
                      }
                  }
              }
              System.exit(0);
          }
      }

      class ChildComponent extends Component {
          public ChildComponent() {
              super();
          }

          boolean keyEventProcessed = false;
          public synchronized void processKeyEvent(KeyEvent e) {
              keyEventProcessed = true;
              System.out.println("processKeyEvent called");
              System.out.flush();
              super.processKeyEvent(e);
              System.out.println("processKeyEvent done");
              System.out.flush();
              notifyAll();
          }
      }

      class DummyKeyListener extends KeyAdapter {
      }

      --- Output ---
      %/net/sword/export3/JDK1.4.0beta-b36/solaris/bin/java -version
      java version "1.4.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b36)
      Java HotSpot(TM) Client VM (build 1.4beta-B36, mixed mode)
      %/net/sword/export3/JDK1.4.0beta-b36/solaris/bin/java ComponentTest5
      Waiting
      ^C
      %

      ======================================================================

            son Oleg Sukhodolsky (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: