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

fp.bugs 3416 Win32 requestFocus() called on mousedown leaves it down

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      solaris_2.5

      Description

      under win32, calling requestFocus() with the mouse button down seems to leave the mouse button down until the next mouseclick in that same panel.
      >From: ###@###.### (Doug Stein)
      To: java@java
      Subject: Bug report: Erroneous mouse events with AWT on Windows


      Platform: Window95 and WindowsNT (not Solaris/Motif)
      JDK version: JDK-1_0-win32-x86.exe
      Priority: Medium (Low/Medium/High/Critical)

      Synopsis
      --------

      AWT mouse events become scrambled if requestFocus() is called
      while the mouse is down.


      Description and reproducible test case
      --------------------------------------

      This bug only occurs on Window95 and WindowsNT, and does not
      happen with Motif.

      Calling requestFocus() while the mouse is down scrambles subsequent
      mouse events. The following test case demonstrates the problem.
      Removing the requestFocus() call from the code eliminates the bug.

      - Compile and run mousedrag.java:

      javac mousedrag.java
      java mousedrag

      - Perform a drag operation from the blue area on the left to the blue
        area on the right (mouseDown in left, drag, mouseUp in right).
        Notice the corrent stream of mouse events:

          mouseDown x y
          mouseDrag x y
          ...
          mouseUp x y

      - Now perform a drag operation from the red area to the blue area. An
        erroneous stream of mouse events is generated. The (x,y) coordinates
        for many of these events are incorrect. It generates something like
        this:

          mouseDown
          mouseDrag
          mouseUp
          mouseDown
          mouseDrag
          mouseDrag
          ...
          (sometimes a mouseDown event gets injected somewhere in here if you
           drag across the textfield)
          ...
          mouseUp

      - Now move the mouse around over the red area (don't press the mouse
        button). You will get a bunch of erroneous mouseDrag events. The
        red panel seems to think that the mouse is still pressed.


      Workaround
      ----------

      Don't call getFocus() while the mouse is pressed.


      ------------------------------------------------------------------------


      I will be reporting quite a few additional AWT bugs. Please let me
      know if this format for bug reporting is acceptable. I am planning to
      include reproducible test cases with all the bugs. I haven't yet
      mailed in all the bugs I have discovered because writing good test
      cases takes time.

      It would be helpful to know when/if bugs will be fixed. If you could
      send me some email when evaluating these bugs it would be very
      helpful.


      Thanks,

      - Doug

      ----- End Included Message -----

      ----------
      X-Sun-Data-Type: default
      X-Sun-Data-Description: default
      X-Sun-Data-Name: mousedrag.java
      X-Sun-Content-Lines: 56
      X-Sun-Content-Length: 1307
      X-Sun-Charset: us-ascii


      import java.awt.*;

      class smallpanel extends Panel {
        public Dimension minimumSize() {
          return new Dimension(80, 80);
        }
        public Dimension preferredSize() {
          return minimumSize();
        }
      }

      public class mousedrag extends Frame {
        public static void main(String argv[]) {
          new mousedrag();
        }

        private TextField textfield;
        private Panel topPanel, leftPanel, rightPanel;
        
        public mousedrag() {
          textfield = new TextField("TextField");
          topPanel = new smallpanel();
          topPanel.setBackground(Color.red);
          leftPanel = new smallpanel();
          leftPanel.setBackground(Color.blue);
          rightPanel = new smallpanel();
          rightPanel.setBackground(Color.blue);
          
          add("Center", textfield);
          add("North", topPanel);
          add("West", leftPanel);
          add("East", rightPanel);
          
          show();
          resize(preferredSize());
          validate();
        }

        public boolean mouseDown(Event e, int x, int y) {
          if (e.target == topPanel)
            textfield.requestFocus();
          System.out.println("mouseDown " + x + " " + y);
          return true;
        }
        
        public boolean mouseUp(Event e, int x, int y) {
          System.out.println("mouseUp " + x + " " + y);
          return true;
        }
        
        public boolean mouseDrag(Event e, int x, int y) {
          System.out.println("mouseDrag " + x + " " + y);
          return true;
        }
      }

        Attachments

          Activity

            People

            Assignee:
            feckssunw Fred Ecks (Inactive)
            Reporter:
            bhagen Benjamin Hagen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: