The attached fixes improve the working of Popup and JPopupMenu in non-Swing toplevel containers.
2006-01-27 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/plaf/basic/BasicPopupMenuUI.java (PopupMenuHandler.popupMenuWillBecomeInvisible): Fixed to also handle non-Swing toplevel containers. (PopupMenuHandler.popupMenuWillBecomeVisible): Fixed to also handle non-Swing toplevel containers. * javax/swing/Popup.java (JWindowPopup.JWindowPopup()): Correctly set parent window on popup. /Roman
Index: javax/swing/Popup.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/Popup.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- javax/swing/Popup.java 9 Jan 2006 16:37:03 -0000 1.8 +++ javax/swing/Popup.java 27 Jan 2006 10:35:11 -0000 1.9 @@ -161,7 +161,7 @@ super(owner, contents, x, y); this.contents = contents; - window = new JWindow(); + window = new JWindow(SwingUtilities.getWindowAncestor(owner)); window.getContentPane().add(contents); window.setLocation(x, y); window.setFocusableWindowState(false); Index: javax/swing/plaf/basic/BasicPopupMenuUI.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicPopupMenuUI.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- javax/swing/plaf/basic/BasicPopupMenuUI.java 4 Nov 2005 18:47:46 -0000 1.15 +++ javax/swing/plaf/basic/BasicPopupMenuUI.java 27 Jan 2006 10:35:11 -0000 1.16 @@ -271,11 +271,10 @@ // by the top - level window that this popup belongs to. Component invoker = popupMenu.getInvoker(); - RootPaneContainer rootContainer = (RootPaneContainer) SwingUtilities - .getRoot(invoker); + Component rootContainer = SwingUtilities.getRoot(invoker); if (rootContainer != null) { - ((Container) rootContainer).removeComponentListener(topWindowListener); + rootContainer.removeComponentListener(topWindowListener); // If this popup menu is the last popup menu visible on the screen, // then @@ -284,11 +283,13 @@ boolean topLevelMenu = (popupMenu.getInvoker() instanceof JMenu) && ((JMenu) popupMenu.getInvoker()).isTopLevelMenu(); - if (topLevelMenu || !(popupMenu.getInvoker() instanceof MenuElement)) + if ((topLevelMenu || !(popupMenu.getInvoker() instanceof MenuElement)) + && rootContainer instanceof RootPaneContainer) { + RootPaneContainer rpContainer = (RootPaneContainer) rootContainer; // set glass pane not to interrupt mouse events and remove // mouseInputListener - Container glassPane = (Container) rootContainer.getGlassPane(); + Container glassPane = (Container) rpContainer.getGlassPane(); glassPane.setVisible(false); glassPane.removeMouseListener(mouseInputListener); mouseInputListener = null; @@ -307,17 +308,18 @@ // ComponentEvents fired by it. We need to cancel this popup menu // if topWindow to which this popup belongs was resized or moved. Component invoker = popupMenu.getInvoker(); - RootPaneContainer rootContainer = (RootPaneContainer) SwingUtilities - .getRoot(invoker); - ((Container) rootContainer).addComponentListener(topWindowListener); + Component rootContainer = SwingUtilities.getRoot(invoker); + rootContainer.addComponentListener(topWindowListener); // Set the glass pane to interrupt all mouse events originating in root // container - if (mouseInputListener == null) + if (mouseInputListener == null + && rootContainer instanceof RootPaneContainer) { - Container glassPane = (Container) rootContainer.getGlassPane(); + RootPaneContainer rpContainer = (RootPaneContainer) rootContainer; + Container glassPane = (Container) rpContainer.getGlassPane(); glassPane.setVisible(true); - mouseInputListener = new MouseInputHandler(rootContainer); + mouseInputListener = new MouseInputHandler(rpContainer); glassPane.addMouseListener(mouseInputListener); glassPane.addMouseMotionListener(mouseInputListener); }