[ImageJ-devel] Funny menu issue with ImageJ2: a tale of frustration and resolution
Johannes Schindelin
Johannes.Schindelin at gmx.de
Tue Jul 3 22:33:11 CDT 2012
Hi all,
I debugged a funny issue with ImageJ2 on Linux, Java 1.6.0_24, that Curtis
pointed out to me: if you click on the File menu, do _not_ release the
mouse button, and then move to the 'Quit' menu item and release the mouse
button, ImageJ does not execute the QuitProgram plugin. If you click on
"File" (releasing the mouse before going on), it works.
A little Googling suggested that enableInputMethods(false) on the JMenuBar
and/or JMenuItems could fix the problem. It indeed fixes the issue that
MouseMotionListeners would not get any events while the mouse is over the
menus, but it does not fix the issue that the ActionEvent is never fired.
A couple of hours debugging later, I find that calling the Fiji Script
Editor and executing a Beanshell script to inspect the state of the
JMenuBar miraculously fixes the problem.
Further inspection of the state before and after calling the Beanshell
script -- which is now empty because that still miraculously fixes the
problem -- I see that the class MouseGrabber (which is an inner class of
javax.swing.plaf.basic.BasicPopupMenuUI) intercepts the mouse drag event
and does not let Handler (an inner class of
javax.swing.plaf.basic.BasicMenuUI) handle it. For some reason, running a
simple Beanshell script in the Script Editor removes the ChangeListener
that adds the MouseGrabber to the AWTEventListeners and all is fine.
(Note: I was unable to pin down what exactly triggers that; just
instantiating the Beanshell interpreter was not enough, there was also
some overzealous threading necessary, of which the Script Editor has a
lot.)
During my debugging efforts, I also found that the problem really only
occurs if the menu item you release the mouse on is in the clipping area
of the frame owning the JMenuBar. So for me, File>Open... and
File>New>Image... works, and even File>New>Internal Clipboard, but
File>New>External Clipboard (which has no overlap with the ImageJ frame)
does not. It will only trigger if you click on File, release the mouse,
and then walk your way to the menu item.
Alas, after a couple of hours of debugging, I finally had a good idea: try
out Java 1.6.0 Update 33 (I tested with Update 24). And lo and behold, the
issue is fixed.
Sigh,
Dscho
P.S.: Of course, Ubuntu still has 6u24 since that is the latest OpenJDK
version. You gotta love Oracle for their brilliant Open Source strategy!
More information about the ImageJ-devel
mailing list