0

For the following:

    private class LabelViewMouseListener extends MouseAdapter
    {
        private Camera ivCamera;

        private LabelViewMouseListener( Camera camera )
        {
            ivCamera = camera;
        }

        @Override
        public void mouseDoubleClick( MouseEvent e )
        {
            startCameraViewer( ivCamera );
        }

        @Override
        public void mouseUp( MouseEvent e )
        {
            ivCamera.getPopupMenu().setVisible( true );
        }
    }

The idea is to get the menu on a click, yet start the viewer on a double click.

When the mouse "clicks", the mouseUp event fires. This brings up the popup menu. The menu positions itself just under the mouse pointer, so the double click does not register as the second click is now absorbed by the menu. If I am very quick and just twitch the mouse enough, I can sometimes get the mouseDoubleClick to fire.

Short of grafting special click abilities onto my users, how do I get this to work as desired?

Big Guy
  • 332
  • 1
  • 13

2 Answers2

0
1. I find it weird for you to override mouseDoubleClick and mouseUp as they aren't methods of MouseAdapter. Unless you are using a library different then `java.awt.event`.
  1. If you want to activate an action only on double click (without triggering one click action), the general idea is you need to set a timer to delay a firing event.

This question is already discussed in the following links, you can have a look at them:

Java : detect triple-click without firing double-click

Distinguish between a single click and a double click in Java

Edit: It appears you are using SWT, not AWT so my answer is irrelevant. I will put this here just in case someone else makes the same mistake like me.

Hung Vu
  • 443
  • 3
  • 15
0

Ok, so I added:

  synchronized (this)
            {
                try
                {
                    wait( Display.getCurrent().getDoubleClickTime() );
                }
                catch (InterruptedException e1)
                {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }

to the mouseUp. It still doesn't work, except almost by chance. It's as if once the mouse event is triggered, a second event mostly is discarded, but sometimes gets through.

Sigh.

I took out the mouseDoubleClick and added

        if ((e.stateMask & SWT.CTRL) != 0)
            {
                startCameraViewer( ivCamera );

                return;
            }

to the top of mouseUp, which has the benefit of at least acting consistently.

Big Guy
  • 332
  • 1
  • 13