Detecting popup display
800382Dec 1 2004 — edited Dec 2 2004Anyone have a way to detect when a popup menu will be shown?
- In theory, one could use HierarchyEvents in Java 1.4 to detect a show/hide, but this seems a little flaky. It relies solely on a flag in the event (SHOWING_CHANGED), which is okay, I guess... in 1.4.
- ContainerListener can tell you if a popup has been added (or at least you can check the component that was added and see if it has a JPopupMenu in it).
- com.sun.java.accessibility.util.TopLevelWindowListener can tell you like ComponentListener, if the popup shows in a window (like if it hangs over the frame)
- I can't use PopupMenuListener.popupMenuWillBecomeVisible() because I don't have any reference to the popup menu in question. The menu could be a right-click popup which could be created when needed and therefore doesn't exist til just before it's shown, so no chance to add a listener.
But the problem I'm finding now is that I go thru this step to show/hide the menu items in the menubar for this capture process I'm doing. Once this happens, the ContainerListener way no longer works. It appears that the popup that is shown is not being properly disposed of in the capture process, thus effecting the notification of the popup showing.
Any thoughts?