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

Key Event not delivered properly with a lightweight container

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.1.4
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_95

      Description



      Name: dgC58589 Date: 11/13/97


      I had submitted this bug earlier which was
      returned as a duplicate of 4071215. I did not
      find the bug thru JDC at that time. I saw it
      today and do not think that mine is a duplicate
      of that bug. So, I submit the bug again.

      If in a frame I add a lightweight
      container and a heavyweight container (Panel),
      KEY EVENTS are not being dispatched properly.

      If I have both as heavyweight container, key
      events are dispatched properly. If there is only
      a lightweight container, key events are not
      dispatched properly too.

      MOUSE Events work fine in all cases. But
      the presence of LIGHTWEIGHT components cause
      KEY EVENTS NOT TO BE FORWARDED SUCCESSFULLY
      TO OTHER COMPONENTS.
      --------------------------------------------------

      import java.awt.*;
      import java.awt.event.*;

      //THIS IS A LIGHTWEIGHT COMPONENT
      class MyPanel1 extends Container {
          public MyPanel1() {
              enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
          }

          public void paint(Graphics g) {
              Dimension d = getSize();
              g.setColor(Color.red);
              g.fillRect(0, 0, d.width, d.height);
          }

          protected void processMouseEvent(MouseEvent e) {
              System.out.println("1 " + e);
              super.processMouseEvent(e);
          }

          protected void processKeyEvent(KeyEvent e) {
              //THIS IS NOT BEING RECEIVED
              System.out.println("1 " + e);
              super.processKeyEvent(e);
          }

          public Dimension getPreferredSize() {
              return new Dimension(100, 100);
          }
      }

      //HEAVYWEIGHT COMPONENT
      class MyPanel2 extends Panel {
          public MyPanel2() {
              enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
          }

          public void paint(Graphics g) {
              Dimension d = getSize();
              g.setColor(Color.yellow);
              g.fillRect(0, 0, d.width, d.height);
          }

          protected void processMouseEvent(MouseEvent e) {
              System.out.println("2 " + e);
          }

          protected void processKeyEvent(KeyEvent e) {
              System.out.println("2 " + e);
              super.processKeyEvent(e);
          }

          public Dimension getPreferredSize() {
              return new Dimension(100, 100);
          }
      }

      public class Test303 extends Panel {
           public Test303() {
               enableEvents(AWTEvent.KEY_EVENT_MASK);
           }

           protected void processKeyEvent(KeyEvent e) {
               System.out.println("3 " + e);
               super.processKeyEvent(e);
          }
          public static void main(String[] args) {
              Frame frame = new Frame();
              Test303 t303 = new Test303();
              t303.setLayout(new BorderLayout());
              MyPanel1 p1 = new MyPanel1();
              MyPanel2 p2 = new MyPanel2();
              t303.add(p1, "East"); //IF THIS IS COMMENTED OUT, KEY
                                    //EVENTS ARE RECEIVED NORMALLY BY
                                    //p2, A HEAVYWEIGHT COMPONENT
              t303.add(p2, "West"); //IF THIS IS COMMENTED OUT, KEY
                                    //EVENTS ARE NOT RECEIVED BY p1,
                                    //WHICH IS A LIGHTWEIGHT COMPONENT,
                                    //but are received by the Frame only
              //IN THIS SCENARIO,
              //KEY EVENTS are not received normally by
              //either MyPanel1 or MyPanel2 but
              //by the Frame.

              //THIS IS NOT A CONSISTENT BEHAVOUR. Lightweight containers
              //are causing key events not to be forwarded to the approriate
              //container successfully.
              frame.add(t303);
              frame.addKeyListener(
                  new KeyAdapter() {
                      public void keyPressed(KeyEvent e) {
                          System.out.println("4 " + e);
                      }
                  });
              frame.setSize(200, 200);
              frame.setVisible(true);
          }
      }
      (Review ID: 19385)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                son Oleg Sukhodolsky (Inactive)
                Reporter:
                dgrahamcsunw David Graham-cumming (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: