if (desktopPane == null) return frame.getDesktopIcon().getBounds();
  protected Rectangle getBoundsForIconOf(JInternalFrame frame)  {    // IconRects has no order to it.    // The icon _must_ be placed in the first free slot (working from     // the bottom left corner)    // The icon also must not be placed where another icon is placed     // (regardless whether that frame is an icon currently or not)    JDesktopPane desktopPane = frame.getDesktopPane();    Rectangle paneBounds = desktopPane.getBounds();    Insets insets = desktopPane.getInsets();    Dimension pref = frame.getDesktopIcon().getPreferredSize();    if (desktopPane == null)      return frame.getDesktopIcon().getBounds();    Component[] frames = desktopPane.getComponents();    int count = 0;    for (int i = 0, j = 0; i < frames.length; i++)      if (frames[i] instanceof JDesktopIcon          || frames[i] instanceof JInternalFrame          && ((JInternalFrame) frames[i]).getWasIcon() && frames[i] != frame)	count++;    iconRects = new Rectangle[count];    for (int i = 0, j = 0; i < frames.length; i++)      if (frames[i] instanceof JDesktopIcon)	iconRects[--count] = frames[i].getBounds();      else if (frames[i] instanceof JInternalFrame               && ((JInternalFrame) frames[i]).getWasIcon()               && frames[i] != frame)	iconRects[--count] = ((JInternalFrame) frames[i]).getDesktopIcon()	                      .getBounds();    int startingX = insets.left;    int startingY = paneBounds.height - insets.bottom - pref.height;    Rectangle ideal = new Rectangle(startingX, startingY, pref.width,                                    pref.height);    boolean clear = true;    while (iconRects.length > 0)      {	clear = true;	for (int i = 0; i < iconRects.length; i++)	  {	    if (iconRects[i] != null && iconRects[i].intersects(ideal))	      {		clear = false;		break;	      }	  }	if (clear)	  return ideal;	startingX += pref.width;	if (startingX + pref.width > paneBounds.width - insets.right)	  {	    startingX = insets.left;	    startingY -= pref.height;	  }	ideal.setBounds(startingX, startingY, pref.width, pref.height);      }    return ideal;  }