Java MouseListener - Events
-
22-08-2019 - |
Question
Does any know if the following is the expected behaviors in terms of what MouseEvent
s are fired? One seems to be missing or consumed elsewhere.
Right-click on
JPanel
and displayJPopupMenu
: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
With
JPopupMenu
still showing left-click somewhere in theJPanel
not in theJPopupMenu
: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.
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 AWTEventListener
s 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