/** The iconifyFrame() code calls this to determine the proper bounds for the desktopIcon. */ protected Rectangle getBoundsForIconOf(JInternalFrame f) { // // Get the icon for this internal frame and its preferred size // JInternalFrame.JDesktopIcon icon = f.getDesktopIcon(); Dimension prefSize = icon.getPreferredSize(); // // Get the parent bounds and child components. // Container c = f.getParent(); if (c == null) { c = f.getDesktopIcon().getParent(); } if (c == null) { /* the frame has not yet been added to the parent; how about (0,0) ?*/ return new Rectangle(0, 0, prefSize.width, prefSize.height); } Rectangle parentBounds = c.getBounds(); Component[] components = c.getComponents(); // // Iterate through valid default icon locations and return the // first one that does not intersect any other icons. // Rectangle availableRectangle = null; JInternalFrame.JDesktopIcon currentIcon = null; int x = 0; int y = parentBounds.height - prefSize.height; int w = prefSize.width; int h = prefSize.height; boolean found = false; while (!found) { availableRectangle = new Rectangle(x, y, w, h); found = true; for (int i = 0; i < components.length; i++) { // // Get the icon for this component // if (components[i] instanceof JInternalFrame) { currentIcon = ((JInternalFrame) components[i]).getDesktopIcon(); } else if (components[i] instanceof JInternalFrame.JDesktopIcon) { currentIcon = (JInternalFrame.JDesktopIcon) components[i]; } else /* found a child that's neither an internal frame nor an icon. I don't believe this should happen, but at present it does and causes a null pointer exception. Even when that gets fixed, this code protects against the npe. hania */ continue; // // If this icon intersects the current location, get next location. // if (!currentIcon.equals(icon)) { if (availableRectangle.intersects(currentIcon.getBounds())) { found = false; break; } } } if (currentIcon == null) /* didn't find any useful children above. This probably shouldn't happen, but this check protects against an npe if it ever does (and it's happening now) */ return availableRectangle; x += currentIcon.getBounds().width; if (x + w > parentBounds.width) { x = 0; y -= h; } } return (availableRectangle); }