One of our customers reported an exception in our application. The problem is that I completely cannot understand how this error can be reproduced.
Here is the code:
btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { popup.show(btn, 3, btn.getHeight()); } });
Notes:
btn
is a final local variable of type JButton
.popup
is the final local variable of type JPopupMenu
.
The following exception was thrown:
java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location at java.awt.Component.getLocationOnScreen_NoTreeLock(Unknown Source) at java.awt.Component.getLocationOnScreen(Unknown Source) at javax.swing.JPopupMenu.show(Unknown Source) at fr.def.iss.vd2.mod_site_watcher_gui.SiteElementPanel$4.actionPerformed(SiteElementPanel.java:117) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.focusLost(Unknown Source) at java.awt.Component.processFocusEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source) at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source) at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
As far as I understand, the show
method complains that btn
not displayed. How is it possible that btn
not displayed when its actionPerformed
method is actionPerformed
?
The strangest thing about this stacktrace is that the actionPerformed
method seems to fire when FocusEvent
(a focusLost
) is focusLost
.
The question is: can you explain how this can happen on the stack?
Epilogue
Thanks to the suggestion of trashgod, I found the problem.
On Windows , when a button disappears when it is clicked, then its ActionListeners start as if the button were clicked. This behavior is observed on Windows, but not on Linux.
I registered an error in the Oracle / Sun database. here's a link:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7115421
(this link will become valid within a few days after it is considered by the Java team).
Thank you for your help. Answers from trashgod and Thomas helped a lot.
source share