Index: javax/swing/JPopupMenu.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/JPopupMenu.java,v retrieving revision 1.19 diff -u -r1.19 JPopupMenu.java --- javax/swing/JPopupMenu.java 21 Jul 2005 14:59:31 -0000 1.19 +++ javax/swing/JPopupMenu.java 8 Sep 2005 17:04:00 -0000 @@ -556,58 +556,70 @@ this.visible = visible; if (old != isVisible()) { - firePropertyChange("visible", old, isVisible()); - if (visible) - { - firePopupMenuWillBecomeVisible(); - Container rootContainer = (Container) SwingUtilities.getRoot(invoker); + firePropertyChange("visible", old, isVisible()); + if (visible) + { + firePopupMenuWillBecomeVisible(); + Container rootContainer = (Container) SwingUtilities.getRoot(invoker); + Dimension screenSize = getToolkit().getScreenSize(); + + boolean fit = true; + Dimension size; - boolean fit = true; - Dimension size; + // Determine the size of the popup menu + if (this.getSize().width == 0 && this.getSize().width == 0) + size = this.getPreferredSize(); + else + size = this.getSize(); - // Determine the size of the popup menu - if (this.getSize().width == 0 && this.getSize().width == 0) - size = this.getPreferredSize(); - else - size = this.getSize(); + if ((size.width > (rootContainer.getWidth() - popupLocation.x)) + || (size.height > (rootContainer.getHeight() - popupLocation.y))) + fit = false; + if (lightWeightPopupEnabled && fit) + popup = new LightWeightPopup(this); + else + { + if (fit) + popup = new MediumWeightPopup(this); + else + popup = new HeavyWeightPopup(this); + } + if (popup instanceof LightWeightPopup + || popup instanceof MediumWeightPopup) + { + JLayeredPane layeredPane; + layeredPane = SwingUtilities.getRootPane(invoker).getLayeredPane(); + Point p = new Point(popupLocation.x, popupLocation.y); + SwingUtilities.convertPointFromScreen(p, layeredPane); + + if (size.width + popupLocation.x > screenSize.width) + popupLocation.x -= size.width; + if (size.height + popupLocation.y > screenSize.height) + popupLocation.y -= size.height; + + popup.show(p.x, p.y, size.width, size.height); + } + else + { + // Subtract insets of the top-level container if popup menu's + // top-left corner is inside it. + Insets insets = rootContainer.getInsets(); - if ((size.width > (rootContainer.getWidth() - popupLocation.x)) - || (size.height > (rootContainer.getHeight() - popupLocation.y))) - fit = false; - if (lightWeightPopupEnabled && fit) - popup = new LightWeightPopup(this); - else - { - if (fit) - popup = new MediumWeightPopup(this); - else - popup = new HeavyWeightPopup(this); - } - if (popup instanceof LightWeightPopup - || popup instanceof MediumWeightPopup) - { - JLayeredPane layeredPane; - layeredPane = SwingUtilities.getRootPane(invoker) - .getLayeredPane(); - Point p = new Point(popupLocation.x, popupLocation.y); - SwingUtilities.convertPointFromScreen(p, layeredPane); - popup.show(p.x, p.y, size.width, size.height); - } - else - { - // Subtract insets of the top-level container if popup menu's - // top-left corner is inside it. - Insets insets = rootContainer.getInsets(); - popup.show(popupLocation.x - insets.left, - popupLocation.y - insets.top, size.width, - size.height); - } - } - else - { - firePopupMenuWillBecomeInvisible(); - popup.hide(); - } + if (size.width + popupLocation.x > screenSize.width) + popupLocation.x -= size.width; + if (size.height + popupLocation.y > screenSize.height) + popupLocation.y -= size.height; + + popup.show(popupLocation.x - insets.left, + popupLocation.y - insets.top, + size.width, size.height); + } + } + else + { + firePopupMenuWillBecomeInvisible(); + popup.hide(); + } } }