protected void resizeDesktop() {
    int x = 0;
    int y = 0;
    JScrollPane scrollPane = getScrollPane();
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
      JInternalFrame allFrames[] = desktop.getAllFrames();
      for (int i = 0; i < allFrames.length; i++) {
        if (allFrames[i].getX() + allFrames[i].getWidth() > x) {
          x = allFrames[i].getX() + allFrames[i].getWidth();
        }
        if (allFrames[i].getY() + allFrames[i].getHeight() > y) {
          y = allFrames[i].getY() + allFrames[i].getHeight();
        }
      }
      Dimension d = scrollPane.getVisibleRect().getSize();
      if (scrollPane.getBorder() != null) {
        d.setSize(
            d.getWidth() - scrollInsets.left - scrollInsets.right,
            d.getHeight() - scrollInsets.top - scrollInsets.bottom);
      }

      if (x <= d.getWidth()) {
        x = ((int) d.getWidth()) - 20;
      }
      if (y <= d.getHeight()) {
        y = ((int) d.getHeight()) - 20;
      }
      desktop.setAllSize(x, y);
      scrollPane.invalidate();
      scrollPane.validate();
    }
  }
示例#2
0
  /** Description of the Method */
  private void buildChildMenus() {
    JInternalFrame[] array = desktop.getAllFrames();

    // update window organization commands
    cascadeCommand.setEnabled(array.length > 0);
    tileHCommand.setEnabled(array.length > 0);
    tileVCommand.setEnabled(array.length > 0);
    arrangeHCommand.setEnabled(array.length > 0);
    arrangeVCommand.setEnabled(array.length > 0);

    if (array.length == 0) {
      return;
    }

    addSeparator();

    for (int i = 0; i < array.length; i++) {
      ChildMenuItem 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);
    }
  }