Question

Does any know if the following is the expected behaviors in terms of what MouseEvents are fired? One seems to be missing or consumed elsewhere.

  1. Right-click on JPanel and display JPopupMenu:

    MousePressed java.awt.event.MouseEvent[MOUSE_PRESSED,
      (469,347),absolute(2214,490),button=3,modifiers=Meta+Button3,
      extModifiers=Button3,clickCount=1]
    
    MouseReleased java.awt.event.MouseEvent[MOUSE_RELEASED,
      (469,347),absolute(2214,490),button=3,modifiers=Meta+Button3,
      extModifiers=Meta,clickCount=1]
    
    MouseClicked java.awt.event.MouseEvent[MOUSE_CLICKED,
      (469,347),absolute(2214,490),button=3,modifiers=Meta+Button3,
      extModifiers=Meta,clickCount=1]
    

    So far so good all 3 from button 3 and in correct order

  2. With JPopupMenu still showing left-click somewhere in the JPanel not in the JPopupMenu:

    What happened to the MousePressed event?

    MouseReleased java.awt.event.MouseEvent[MOUSE_RELEASED,
      (452,339),absolute(2197,482),button=1,modifiers=Button1,clickCount=1]
    
    MouseClicked java.awt.event.MouseEvent[MOUSE_CLICKED,
      (452,339),absolute(2197,482),button=1,modifiers=Button1,clickCount=1]
    

Thanks in Advance.

Was it helpful?

Solution

So the event that causes the popup menu to close has disappeared.

IIRC, exactly how this is implemented changed from 1.5 to 1.6. In 1.5 there is a glasspane, in 1.6 AWTEventListeners are used. See BasicPopupMenuUI sources for details. It looks as if you can (globally) stop the event being consumed with:

UIManager.put("PopupMenu.consumeEventOnClose", false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top