code: private void buildChildMenus() {
          int i;
          JInternalFrame[] array = desktop.getAllFrames();
  
          add(cascade);
          add(tile);
          add(minAll);
          add(restoreAll);
          if (array.length > 0) {
              addSeparator();
          }
          cascade.setEnabled(array.length > 0);
          tile.setEnabled(array.length > 0);
          minAll.setEnabled(desktop.deIconifiedFrames() > 0);
          restoreAll.setEnabled(desktop.iconifiedFrames() > 0);
  
          ChildMenuItem menu;
          for (i = 0; i < array.length; i++) {
              menu = new ChildMenuItem(array[i]);
              menu.setState(i == 0);
              menu.addActionListener(new ActionListener() {
  
                  public void actionPerformed(ActionEvent ae) {
                      JInternalFrame frame =
                              ((ChildMenuItem) ae.getSource()).getFrame();
                      frame.moveToFront();
                      try {
                          frame.setSelected(true);
                      } catch (PropertyVetoException e) {
                          e.printStackTrace();
                      }
                  }
              });
              menu.setIcon(array[i].getFrameIcon());
              add(menu);
          }
      }
docs: /* Sets up the children menus depending on the current desktop state