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

Click count is > 1 on first click in newly opened frame

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: jk109818 Date: 04/04/2003


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java Hotspot(TM) Client VM (build 1.4.1-b21, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]
      (also occurs on OSX VM 1.3.1 and prior windows VMs)

      A DESCRIPTION OF THE PROBLEM :
      When java.awt.Robot is used to generate click events immediately
      after a frame opens, sometimes the very first mouse event on that
      frame registers a click count > 1.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      0. Add an AWTEventListener to the system queue to examine
      mouse events
      1. Create a frame with a JList
      2. Create a second frame with a JList
      4. Show the first frame
      5. Use java.awt.Robot to click in the first list, auto delay = 0
      6. Close the first frame, show the second
      7. Use java.awt.Robot to click in the second list
      8. Close the second frame
      9. Dispose both frames
      10. Go to #1 above, repeat all steps

      The first list will often get mouse events with a click count > 1

      Code to test for this bug exists at
      http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/abbot/abbot/test/
      abbot/PlatformTest.java?rev=1.9&content-type=text/vnd.viewcvs-
      markup



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I'm not sure what the definition of a multi-click is, but I would
      assume the following are required:

      1) no intervening mouse motion
      2) subsequent clicks are on the same component

      Given that the clicks are on different components, a click on one
      component should not count towards a multi-click on another.

      The problem is not likely as straightforward as it might seem, since
      only the first list seems to be encountering the multi-clicks.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.util.*;

      /** Demonstrate click count > 1 on the first click in a component. */
      public class MultiClickBug {

          private static ArrayList events = new ArrayList();
          private static Robot robot;

          private static void waitForVisibility(final Window win, boolean visible) {
              long start = System.currentTimeMillis();
              if (visible) {
                  while (!win.isVisible() || !win.isShowing()) {
                      if (System.currentTimeMillis() - start > 5000)
                          throw new RuntimeException("Window failed to show");
                      robot.delay(100);
                  }
              }
              else {
                  while (win.isVisible() || win.isShowing()) {
                      if (System.currentTimeMillis() - start > 5000)
                          throw new RuntimeException("Window failed to show");
                      robot.delay(100);
                  }
              }
          }

          private static void showWindow(final Window w) throws Throwable {
              EventQueue.invokeAndWait(new Runnable() {
                  public void run() {
                      w.pack();
                      w.show();
                  }
              });
              waitForVisibility(w, true);
          }

          private static void click(Component c) throws Throwable {
              Point p = c.getLocationOnScreen();
              p.translate(c.getWidth()/2, c.getHeight()/2);
              robot.mouseMove(p.x, p.y);
              robot.mousePress(MouseEvent.BUTTON1_MASK);
              robot.mouseRelease(MouseEvent.BUTTON1_MASK);
              // Wait for the events to be processed
              EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
              while (eq.peekEvent() != null) {
                  robot.waitForIdle();
              }
          }

          /** This will fail if the multi-click frame bug shows up somewhere we
              don't expect it.
          */
          private static void multiClickFrameBug() throws Throwable {
              robot = new Robot();

              String[] data = { "one", "two", "three", "four", "five" };
              JFrame frame1 = new JFrame("Multi-click Bug");
              JList list1 = new JList(data);
              list1.setName("List 1");
              frame1.getContentPane().add(list1);
              frame1.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent we) {
                      System.exit(0);
                  }
              });
              
              MouseListener ml = new MouseAdapter() {
                  public void mouseClicked(MouseEvent me) {
                      events.add(me);
                  }
              };
              list1.addMouseListener(ml);

              showWindow(frame1);
              click(list1);
              frame1.hide();
              waitForVisibility(frame1, false);
              showWindow(frame1);
              click(list1);

              long start = System.currentTimeMillis();
              while (events.size() < 2) {
                  if (System.currentTimeMillis() - start > 5000) {
                      System.err.println("Timed out waiting for click events");
                      System.exit(1);
                  }
              }

              // Both events should have a click count of one
              int errs = 0;
              MouseEvent me = (MouseEvent)events.get(0);
              if (me.getClickCount() != 1) {
                  ++errs;
                  System.err.println("Incorrect click count on " + me.getSource());
              }
              me = (MouseEvent)events.get(1);
              if (me.getClickCount() != 1) {
                  ++errs;
                  System.err.println("Incorrect click count on " + me.getSource());
              }
              if (errs == 0) {
                  System.out.println("No bugs encountered");
              }
              System.exit(errs);
          }

          public static void main(String[] args) {
              try {
                  multiClickFrameBug();
              }
              catch(Throwable thr) {
                  thr.printStackTrace();
                  System.exit(0);
              }
          }
      }



      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Delay 200 ms prior to showing a frame.
      (Review ID: 179990)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            denis Denis Fokin (Inactive)
            Reporter:
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: