0

An application had a short popup menu with configuration. After some time the configuration had grown, and I want to call a dialogue instead the popup menu. But when I call the dialog on mouse event, strange things happen. The mouseReleased is called several times in stack. Every time it is called for the same component (the correct one), so, it is not due to calling the same event from several overlaying components.

It seems, that I simply can't call dialogue instead of popup menu, ok. But what is happening?

The adapter:

class ConfigTriggerListener extends MouseAdapter{
    ...
    @Override
    public void mouseReleased(MouseEvent ev) {
      if (ev.isPopupTrigger()) {                  <-- breakpoint

        cont.showScreenModal(ConfigDlg.class, DynProps.createFromValues(ConfigDlg.CONFIG_CONTROL_CLASS, ORundownConfig.class));
      }    
    }
}    

CallStack after right click and pause on the breakpoint:

octopus.client.core.rundown.RundownClock$ConfigTriggerListener.mouseReleased(RundownClock.java:164)
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
java.awt.Component.processMouseEvent(Component.java:6505)
javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
java.awt.Component.processEvent(Component.java:6270)
java.awt.Container.processEvent(Container.java:2229)
java.awt.Component.dispatchEventImpl(Component.java:4861)
java.awt.Container.dispatchEventImpl(Container.java:2287)
java.awt.Component.dispatchEvent(Component.java:4687)
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
java.awt.Container.dispatchEventImpl(Container.java:2273)
java.awt.Window.dispatchEventImpl(Window.java:2719)
java.awt.Component.dispatchEvent(Component.java:4687)
java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
java.awt.EventQueue.access$200(EventQueue.java:103)
java.awt.EventQueue$3.run(EventQueue.java:694)
java.awt.EventQueue$3.run(EventQueue.java:692)
java.security.AccessController.doPrivileged(AccessController.java)
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
java.awt.EventQueue$4.run(EventQueue.java:708)
java.awt.EventQueue$4.run(EventQueue.java:706)
java.security.AccessController.doPrivileged(AccessController.java)
java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • setting in Mouse Properties (Native OS) – mKorbel Dec 03 '14 at 11:00
  • @mKorbel Sorry? As for native OS, it is Win 7. – Gangnus Dec 03 '14 at 11:11
  • yes, for example this is Win7 – mKorbel Dec 03 '14 at 11:17
  • @mKorbel What "this" is win 7? Please, could you write a whole sentence. I can't agree or disagree with you, or take your advice, the amount of info from you is 0. – Gangnus Dec 03 '14 at 11:32
  • sorry are you sure that question in present form can be answerable here, everything depends of your code, for better help sooner post an SSCCE/MCVE, short, runnable, compilable, with hardcoded value in local variables – mKorbel Dec 03 '14 at 11:36
  • the amount of info from you is 0. == thank you so much – mKorbel Dec 03 '14 at 11:37
  • @mKorbel 1. Now it is not 0, thank you. But it seems to me, you wanted to say something different at first. I really didn't understand the comment about Mouse Properties... 2. Why it is not answerable? Somebody could have tried the similar thing - calling something instead of popup menu. As for rewriting he problem code into a separate task, for me it would be MUCH easier to implement another UI solution. I'll try to solve the problem sometimes later at home. – Gangnus Dec 03 '14 at 11:46
  • `calling something instead of popup menu.` - this is standard solution, but thats required really hard work to generate the caused exceptions, ... worse could be only from RepaintManager, e.g. take a value, returns from this Object can do that (I think) :-) – mKorbel Dec 03 '14 at 11:51
  • create undecorated JDialog, maybe better is JWindow, collect all values to JComponents, create a JComponents, add value, use Initial Thread for pack and setVisible, reuse this container for another action (remove all from content pane, must be visible, call for revalidate/repaint, then to hide this contianer), – mKorbel Dec 03 '14 at 11:54
  • I defer to @mKorbel's broader experience on Windows, but [note](https://docs.oracle.com/javase/tutorial/uiswing/components/menu.html#popup) that "The exact gesture that should bring up a popup menu varies by look and feel." If it's now a dialog, why not `mousePressed()`? Are you perhaps seeing the effect of code originally intended to compensate for this cross-platform vagary? Absent a [complete example](http://stackoverflow.com/help/mcve) that exhibits the problem you describe, I'm not sure anyone can answer your question. – trashgod Dec 03 '14 at 11:56
  • @trashgod on mousePressed the ev.isPopupTrigger() is not true yet in Windows. The mousePressed has the same content, due to MAC, but on windows the mouseReleased works. As for mouseClicked, it has the same problem. Maybe, mousePressed, too, I haven't tested on Mac yet. – Gangnus Dec 03 '14 at 12:22
  • @mKorbel I understand I have to do it the other way and I do it now. What I do not understand, how happens this 7 times stacked recursed calling of mouseReleased()? I wouldn't be able to do it voluntary if I wanted to. – Gangnus Dec 03 '14 at 12:25
  • @Gangnus be sure that is not generating multiple events that kills CPU/GPU Latency with empty container without your additional / added value coded in nested classes:-) whats happens if you do that, to test by using empty container without balast, as aside the (various) combinations of AWT/Swing Listener added to one Object can to creates endless loop – mKorbel Dec 03 '14 at 12:38
  • @mKorbel surely I will, but as I said, not now. I am at work and need to do what works, not merely study intestines of Java :-( – Gangnus Dec 03 '14 at 12:57
  • Use `setComponentPopupMenu(javax.swing.JPopupMenu)` to set the PopupMenu and let Swing handle the right-click etc... It will take care of the various platform behaviour – Guillaume Polet Dec 03 '14 at 19:50
  • @GuillaumePolet So, I have to use PopupMenu class for using something INSTEAD of popup menu? – Gangnus Dec 04 '14 at 08:07
  • @Gangnus See this [answer](http://stackoverflow.com/questions/16743427/newbie-jtable-right-click-popup-menu/16744349?s=1|3.4026#16744349) to see how you can set a JPopupMenu to appear upon right-click by using setComponentPopupMenu – Guillaume Polet Dec 04 '14 at 09:22

0 Answers0