/**
  * Removes the desktopIcon from its parent and adds its frame to the parent.
  *
  * @param f the <code>JInternalFrame</code> to be de-iconified
  */
 public void deiconifyFrame(JInternalFrame f) {
   JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
   Container c = desktopIcon.getParent();
   JDesktopPane d = f.getDesktopPane();
   if (c != null && d != null) {
     c.add(f);
     // If the frame is to be restored to a maximized state make
     // sure it still fills the whole desktop.
     if (f.isMaximum()) {
       Rectangle desktopBounds = c.getBounds();
       if (f.getWidth() != desktopBounds.width || f.getHeight() != desktopBounds.height) {
         setBoundsForFrame(f, 0, 0, desktopBounds.width, desktopBounds.height);
       }
     }
     removeIconFor(f);
     if (f.isSelected()) {
       f.moveToFront();
       f.restoreSubcomponentFocus();
     } else {
       try {
         f.setSelected(true);
       } catch (PropertyVetoException e2) {
       }
     }
   }
 }
  /**
   * Removes the frame from its parent and adds its <code>desktopIcon</code> to the parent.
   *
   * @param f the <code>JInternalFrame</code> to be iconified
   */
  public void iconifyFrame(JInternalFrame f) {
    JInternalFrame.JDesktopIcon desktopIcon;
    Container c = f.getParent();
    JDesktopPane d = f.getDesktopPane();
    boolean findNext = f.isSelected();
    desktopIcon = f.getDesktopIcon();
    if (!wasIcon(f)) {
      Rectangle r = getBoundsForIconOf(f);
      desktopIcon.setBounds(r.x, r.y, r.width, r.height);
      setWasIcon(f, Boolean.TRUE);
    }

    if (c == null || d == null) {
      return;
    }

    if (c instanceof JLayeredPane) {
      JLayeredPane lp = (JLayeredPane) c;
      int layer = lp.getLayer(f);
      lp.putLayer(desktopIcon, layer);
    }

    // If we are maximized we already have the normal bounds recorded
    // don't try to re-record them, otherwise we incorrectly set the
    // normal bounds to maximized state.
    if (!f.isMaximum()) {
      f.setNormalBounds(f.getBounds());
    }
    d.setComponentOrderCheckingEnabled(false);
    c.remove(f);
    c.add(desktopIcon);
    d.setComponentOrderCheckingEnabled(true);
    c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
    if (findNext) {
      if (d.selectFrame(true) == null) {
        // The icon is the last frame.
        f.restoreSubcomponentFocus();
      }
    }
  }