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

Shouldn't mousePressed and mouseReleased be called synchroniouse?

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.2.1
    • client-libs
    • Cause Known
    • generic
    • generic

      Name: vi73552 Date: 04/26/99


      I have the following problem, in one of our custom components we react to mouse pressed messages to perform
      some operation, often they first prompt the user for some information, we use a modal dialog box to do this. Now
      the component has also a popup menu and this causes the following problem.

      If the customer clicks with the mouse on the component, the message box starts, but the component even gets the
      released message and the popup starts, too.
      This is really ugly and confusing for the customer!

      After analyzing why this happens I noticed that starting a modal dialog box in mouse pressed causes the mouse
      released message to be propagated to the component before the message box appears, before the mouse pressed
      method is exited.

      Is this a wanted behaviour? This means mousepressed and mousereleased could be interlaced calls.

      I send you a test program, which shows the behavior in detail as attachment.

      For now we use the workaround to manage a flag which gives us the information that the app is in the middle of a
      mouse pressed method and ignore all other events, but this should not be necessary, I think.

      Thank you
          Patrick


      //////////// ATTACHMENT /////////////////////////////////////


      import java.awt.event.MouseEvent;
      import java.awt.event.MouseListener;

      import javax.swing.JFrame;
      import javax.swing.JOptionPane;

      public class Test extends JFrame implements MouseListener
      {
      public Test()
      {
      super("Test");
      addMouseListener(this);
      setSize(200, 200);
      setVisible(true);
      }

      /**
      * MouseListener-Methode.
      */
      public void mouseEntered(MouseEvent e)
      {
      System.err.println("Mouse entered on " + e.getSource().getClass());
      }

      /**
      * MouseListener-Methode.
      */
      public void mousePressed(MouseEvent e)
      {
      System.err.println("\nMouse pressed on " + e.getSource().getClass());

      // here I start a message box
      JOptionPane.showMessageDialog(this, "Dummy message!");


      System.err.println("Mouse pressed finished");

      }

      /**
      * MouseListener-Methode.
      */
      public void mouseReleased(MouseEvent e)
      {
      System.err.println("Mouse released on " + e.getSource().getClass());
      if (e.isPopupTrigger())
      System.err.println("Show popup menu"); // Here a popup menu would be started!
      }

      /**
      * MouseListener-Methode.
      */
      public void mouseClicked(MouseEvent e)
      {
      System.err.println("Mouse clicked on " + e.getSource().getClass());
      }

      /**
      * MouseListener-Methode.
      */
      public void mouseExited(MouseEvent e)
      {
      System.err.println("Mouse exited on " + e.getSource().getClass());
      }

      /**
      * Start the test program.
      */
      public static void main(String[] args)
      {
      new Test();
      }
      }
      (Review ID: 57066)
      ======================================================================

            dav Andrei Dmitriev (Inactive)
            vasya Vassili Igouchkine (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: