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

endless sequence of synthetic mouse drag events

    XMLWordPrintable

    Details

      Description

      J2SE Version (please include all output from java -version flag):
        java version "1.6.0-beta2"
        Java(TM) SE Runtime Environment (build 1.6.0-beta2-b80)
        Java HotSpot(TM) Client VM (build 1.6.0-beta2-b80, mixed mode, sharing)

      Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
        Yes

      Operating System Configuration Information (be specific):
        Windows XP Professional SP2

      Hardware Configuration Information (be specific):
        Intel Pentium III, 730 Mhz, 384 Mb RAM

      Bug Description:
      A swing application that has a component that registers to
      receive synthetic drag events receives an endless sequence
      of them when it looses focus.

      Steps to Reproduce (be specific):

      Consider the attached program. Compile, and run it.
      Then place the pointer over its window, press the left
      mouse button and drag the mouse out of its window.
      Then, without releasing the button, move the focus to
      another window (e.g. the command prompt from which it has
      been run).
      You should see in the command window an endless display
      of the message "dragged: ...". Endless events are fired
      also if the application window gets minimised.
      To stop this, you can place the mouse in the window and
      press the left button.
      The correct behaviour should be to stop generating synthetic
      eventa when the window looses focus.
      Deleted bogus part 1.
      //Here is the test case, as requested by java.net members:

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

      public class DragNonStop extends JPanel implements MouseListener,
          MouseMotionListener {

          public static void main(String[] args){
              javax.swing.SwingUtilities.invokeLater(new Runnable(){
                  public void run(){
                      JFrame frame = new JFrame("DragNonStop");
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      frame.getContentPane().add(new DragNonStop());
                      frame.pack();
                      frame.setVisible(true);
                  }
              });
          }

          public DragNonStop(){
             setPreferredSize(new Dimension(200,300));
             setBackground(Color.white);
             setAutoscrolls(true); // enable synthetic drag events
             addMouseListener(this);
             addMouseMotionListener(this);
          }

          public void mouseEntered(MouseEvent e){}
          public void mouseExited(MouseEvent e){}
          public void mouseClicked(MouseEvent e){}
          public void mousePressed(MouseEvent e){
              System.out.println("pressed: " + e.getX() + " " + e.getY());
          }
          public void mouseReleased(MouseEvent e){
              System.out.println("released: " + e.getX() + " " + e.getY());
          }
          public void mouseMoved(MouseEvent e){
              System.out.println("moved: " + e.getX() + " " + e.getY());
          }
          public void mouseDragged(MouseEvent e){
              System.out.println("dragged: " + e.getX() + " " + e.getY());
          }
      /*
          public void paintComponent(Graphics g) {
              super.paintComponent(g); // paint the background
              Graphics2D g2 = (Graphics2D)g;
              if (isMouseDraggingBox){
                  g2.setPaint(Color.red); // highlight affected shape
                  g2.fill(saveRect);
                  g2.setPaint(Color.black);
                  g2.draw(saveRect);
                  g2.setPaint(Color.gray); // display outline
                  g2.draw(rect);
              } else {
                  g2.setPaint(Color.yellow);
                  g2.fill(rect);
                  g2.setPaint(Color.black);
                  g2.draw(rect);
              }
          }
      */
      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: