Пример #1
0
  private boolean is(boolean first) {
    Container parent = getParent();
    if (parent == null) return false;

    int max = first ? Integer.MAX_VALUE : 0;
    ToolWindowAnchor anchor = getAnchor();
    Component c = null;
    int count = parent.getComponentCount();
    for (int i = 0; i < count; i++) {
      Component component = parent.getComponent(i);
      if (!component.isVisible()) continue;
      Rectangle r = component.getBounds();
      if (anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT) {
        if (first && (max > r.y) || (!first && max < r.y)) {
          max = r.y;
          c = component;
        }
      } else {
        if (first && (max > r.x) || (!first && max < r.x)) {
          max = r.x;
          c = component;
        }
      }
    }

    return c == this;
  }
    @Override
    public void layoutContainer(final Container parent) {
      final int componentCount = parent.getComponentCount();
      if (componentCount == 0) return;
      final EditorEx history = myHistoryViewer;
      final EditorEx editor = componentCount == 2 ? myConsoleEditor : null;

      if (editor == null) {
        parent.getComponent(0).setBounds(parent.getBounds());
        return;
      }

      final Dimension panelSize = parent.getSize();
      if (panelSize.getHeight() <= 0) return;
      final Dimension historySize = history.getContentSize();
      final Dimension editorSize = editor.getContentSize();
      final Dimension newEditorSize = new Dimension();

      // deal with width
      final int width = Math.max(editorSize.width, historySize.width);
      newEditorSize.width = width + editor.getScrollPane().getHorizontalScrollBar().getHeight();
      history.getSoftWrapModel().forceAdditionalColumnsUsage();
      editor
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - editorSize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, editor));
      history
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - historySize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, history));

      // deal with height
      if (historySize.width == 0) historySize.height = 0;
      final int minHistorySize =
          historySize.height > 0
              ? 2 * history.getLineHeight() + (myShowSeparatorLine ? SEPARATOR_THICKNESS : 0)
              : 0;
      final int minEditorSize = editor.isViewer() ? 0 : editor.getLineHeight();
      final int editorPreferred =
          editor.isViewer() ? 0 : Math.max(minEditorSize, editorSize.height);
      final int historyPreferred = Math.max(minHistorySize, historySize.height);
      if (panelSize.height < minEditorSize) {
        newEditorSize.height = panelSize.height;
      } else if (panelSize.height < editorPreferred) {
        newEditorSize.height = panelSize.height - minHistorySize;
      } else if (panelSize.height < editorPreferred + historyPreferred) {
        newEditorSize.height = editorPreferred;
      } else {
        newEditorSize.height = editorPreferred == 0 ? 0 : panelSize.height - historyPreferred;
      }
      final Dimension newHistorySize =
          new Dimension(width, panelSize.height - newEditorSize.height);

      // apply
      editor
          .getComponent()
          .setBounds(0, newHistorySize.height, panelSize.width, newEditorSize.height);
      myForceScrollToEnd.compareAndSet(false, shouldScrollHistoryToEnd());
      history.getComponent().setBounds(0, 0, panelSize.width, newHistorySize.height);
    }
Пример #3
0
  /**
   * Replace the current contents of the frame's content pane.
   *
   * @param panel JPanel of the new contents of the content pane.
   */
  public void replace(JPanel panel) {
    // Removes everything from the content pane.
    for (int i = 0; i < pane.getComponentCount(); i++) {
      pane.remove(i);
    }

    pane.add(panel);
  }
  public static final Component getChildAtLine(
      Container container, Point point, boolean horizontal) {
    if (horizontal) {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component component = container.getComponent(i);
        if (point.x >= component.getX() && point.x < component.getX() + component.getWidth())
          return component;
      }
    } else {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component component = container.getComponent(i);
        if (point.y >= component.getY() && point.y < component.getY() + component.getHeight())
          return component;
      }
    }

    return null;
  }
Пример #5
0
 public static void recursiveSetBackground(Component comp, Color color) {
   if (comp instanceof JToolBar || comp instanceof JButton) return;
   comp.setBackground(color);
   if (comp instanceof Container) {
     Container cc = (Container) comp;
     for (int i = 0; i < cc.getComponentCount(); i++)
       recursiveSetBackground(cc.getComponent(i), color);
   }
 }
 public static void setAllOpaque(Container container, boolean opaque) {
   if (container instanceof JComponent) {
     ((JComponent) container).setOpaque(opaque);
     for (int i = 0; i < container.getComponentCount(); i++) {
       Component component = container.getComponent(i);
       if (component instanceof Container) setAllOpaque((Container) component, opaque);
     }
   }
 }
  public static int countComponents(Container container) {
    int num = 1;
    for (int i = 0; i < container.getComponentCount(); i++) {
      Component comp = container.getComponent(i);
      if (comp instanceof Container) num += countComponents((Container) comp);
      else num++;
    }

    return num;
  }
  public static final Component getVisibleChildAt(Container container, Point point) {
    for (int i = 0; i < container.getComponentCount(); i++) {
      Component component = container.getComponent(i);
      if (component.isVisible()
          && component.contains(point.x - component.getX(), point.y - component.getY()))
        return component;
    }

    return null;
  }
Пример #9
0
 @Override
 public Dimension preferredLayoutSize(final Container parent) {
   Dimension result = new Dimension();
   for (int i = 0; i < parent.getComponentCount(); i++) {
     final Dimension prefSize = parent.getComponent(i).getPreferredSize();
     result.width += prefSize.width;
     result.height = Math.max(prefSize.height, result.height);
   }
   return result;
 }
  public static final int getComponentIndex(Component component) {
    if (component != null && component.getParent() != null) {
      Container container = component.getParent();
      for (int i = 0; i < container.getComponentCount(); i++) {
        if (container.getComponent(i) == component) return i;
      }
    }

    return -1;
  }
  public static int getVisibleChildrenCount(Component component) {
    if (component == null || !(component instanceof Container)) return 0;

    int count = 0;
    Container container = (Container) component;

    for (int i = 0; i < container.getComponentCount(); i++)
      if (container.getComponent(i).isVisible()) count++;

    return count;
  }
  public static Component findFirstComponentOfType(Component component, Class nowClass) {
    if (nowClass.isInstance(component)) return component;

    if (component instanceof Container) {
      Container container = (Container) component;
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component firstComponent = findFirstComponentOfType(container.getComponent(i), nowClass);
        if (firstComponent != null) return firstComponent;
      }
    }
    return null;
  }
Пример #13
0
  /**
   * @param aContainer
   * @param aComponentClass
   * @return
   */
  private static Component findComponent(
      final Container aContainer, final Class<? extends Component> aComponentClass) {
    Component result = null;

    final int cnt = aContainer.getComponentCount();
    for (int i = 0; (result == null) && (i < cnt); i++) {
      final Component comp = aContainer.getComponent(i);
      if (aComponentClass.equals(comp.getClass())) {
        result = comp;
      } else if (comp instanceof Container) {
        result = findComponent((Container) comp, aComponentClass);
      }
    }
    return result;
  }
Пример #14
0
 private static void updateSizesFromChildren(DimensionInfo info, boolean min, int[] widths) {
   for (int i = info.getComponentCount() - 1; i >= 0; --i) {
     Component child = info.getComponent(i);
     GridConstraints c = info.getConstraints(i);
     if (c.isUseParentLayout() && child instanceof Container) {
       Container container = (Container) child;
       if (container.getLayout() instanceof GridLayoutManager) {
         updateSizesFromChild(info, min, widths, container, i);
       } else if (container.getComponentCount() == 1
           && container.getComponent(0) instanceof Container) {
         Container childContainer = (Container) container.getComponent(0);
         if (childContainer.getLayout() instanceof GridLayoutManager) {
           updateSizesFromChild(info, min, widths, childContainer, i);
         }
       }
     }
   }
 }
Пример #15
0
  public Dimension preferredLayoutSize(Container parent) {
    Insets insets = parent.insets();
    int ncomponents = parent.countComponents();
    int nrows = getRows();
    int ncols = getColumns();
    int hgap = getHgap();
    int vgap = getVgap();

    if (nrows > 0) {
      ncols = (ncomponents + nrows - 1) / nrows;
    } else {
      nrows = (ncomponents + ncols - 1) / ncols;
    }

    int nComps = parent.getComponentCount();

    int y = insets.top;
    for (int row = 0; row < nrows; row++) {
      int h = 0;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          h = Math.max(h, c.getMinimumSize().height);
        }
      }
      y += h + vgap;
    }

    int x = insets.left;
    for (int col = 0; col < ncols; col++) {
      int w = 0;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          w = Math.max(w, c.getMinimumSize().width);
        }
      }
      x += w + hgap;
    }
    return new Dimension(x, y);
  }
Пример #16
0
    @Override
    public void layoutContainer(final Container parent) {
      assert parent.getComponentCount() == 2; // 1. info; 2. progress

      Component infoPanel = parent.getComponent(0);
      Component progressPanel = parent.getComponent(1);
      int progressPrefWidth = progressPanel.getPreferredSize().width;

      final Dimension size = parent.getSize();
      int maxProgressWidth = (int) (size.width * 0.8);
      int minProgressWidth = (int) (size.width * 0.5);
      if (progressPrefWidth > myProgressWidth) {
        myProgressWidth = progressPrefWidth;
      }
      if (myProgressWidth > maxProgressWidth) {
        myProgressWidth = maxProgressWidth;
      }
      if (myProgressWidth < minProgressWidth) {
        myProgressWidth = minProgressWidth;
      }
      infoPanel.setBounds(0, 0, size.width - myProgressWidth, size.height);
      progressPanel.setBounds(size.width - myProgressWidth, 0, myProgressWidth, size.height);
    }
Пример #17
0
  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Octavio Maia
    label1 = new JLabel();
    comboBox1 = new JComboBox<>();
    label2 = new JLabel();
    data = new JLabel();
    buttonDataNascimento = new JButton();
    buttonCancelar = new JButton();
    buttonAvancar = new JButton();
    separator1 = new JSeparator();
    dialogoCalendar = new JDialog();
    calendar1 = new JCalendar();
    buttonConfirmarDataInicio = new JButton();
    buttonCancelarData = new JButton();

    // ======== this ========
    setTitle("Criar Elei\u00e7\u00e3o");
    setResizable(false);
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    Container contentPane = getContentPane();
    contentPane.setLayout(null);

    // ---- label1 ----
    label1.setText("Tipo de elei\u00e7\u00e3o:");
    label1.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(label1);
    label1.setBounds(10, 10, label1.getPreferredSize().width, 25);

    // ---- comboBox1 ----
    comboBox1.setFont(new Font("Arial", Font.PLAIN, 14));
    comboBox1.setModel(
        new DefaultComboBoxModel<>(
            new String[] {"Assembleia da Rep\u00fablica", "Presid\u00eancia da Rep\u00fablica"}));
    contentPane.add(comboBox1);
    comboBox1.setBounds(125, 10, 215, 25);

    // ---- label2 ----
    label2.setText("Data:");
    label2.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(label2);
    label2.setBounds(10, 50, 101, 25);

    // ---- data ----
    data.setText("dd/mm/aa");
    data.setFont(new Font("Arial", Font.PLAIN, 14));
    contentPane.add(data);
    data.setBounds(125, 50, 115, 25);

    // ---- buttonDataNascimento ----
    buttonDataNascimento.setText("Alterar");
    buttonDataNascimento.setFont(new Font("Arial", Font.PLAIN, 14));
    buttonDataNascimento.addActionListener(e -> buttonDataActionPerformed(e));
    contentPane.add(buttonDataNascimento);
    buttonDataNascimento.setBounds(260, 50, 80, 25);

    // ---- buttonCancelar ----
    buttonCancelar.setText("Cancelar");
    buttonCancelar.setFont(new Font("Arial", Font.PLAIN, 14));
    buttonCancelar.addActionListener(e -> buttonCancelarActionPerformed(e));
    contentPane.add(buttonCancelar);
    buttonCancelar.setBounds(100, 90, 115, 25);

    // ---- buttonAvancar ----
    buttonAvancar.setText("Avan\u00e7ar");
    buttonAvancar.setFont(new Font("Arial", Font.PLAIN, 14));
    buttonAvancar.setEnabled(false);
    buttonAvancar.addActionListener(e -> buttonAvancarActionPerformed(e));
    contentPane.add(buttonAvancar);
    buttonAvancar.setBounds(230, 90, 110, buttonAvancar.getPreferredSize().height);
    contentPane.add(separator1);
    separator1.setBounds(5, 80, 340, 5);

    { // compute preferred size
      Dimension preferredSize = new Dimension();
      for (int i = 0; i < contentPane.getComponentCount(); i++) {
        Rectangle bounds = contentPane.getComponent(i).getBounds();
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
      }
      Insets insets = contentPane.getInsets();
      preferredSize.width += insets.right;
      preferredSize.height += insets.bottom;
      contentPane.setMinimumSize(preferredSize);
      contentPane.setPreferredSize(preferredSize);
    }
    setSize(365, 160);
    setLocationRelativeTo(null);

    // ======== dialogoCalendar ========
    {
      dialogoCalendar.setTitle("Calendario");
      dialogoCalendar.setResizable(false);
      dialogoCalendar.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
      Container dialogoCalendarContentPane = dialogoCalendar.getContentPane();
      dialogoCalendarContentPane.setLayout(null);
      dialogoCalendarContentPane.add(calendar1);
      calendar1.setBounds(0, 0, 210, 155);

      // ---- buttonConfirmarDataInicio ----
      buttonConfirmarDataInicio.setText("Confirmar");
      buttonConfirmarDataInicio.setFont(new Font("Arial", Font.PLAIN, 12));
      buttonConfirmarDataInicio.addActionListener(e -> buttonConfirmarDataActionPerformed(e));
      dialogoCalendarContentPane.add(buttonConfirmarDataInicio);
      buttonConfirmarDataInicio.setBounds(5, 155, 90, 28);

      // ---- buttonCancelarData ----
      buttonCancelarData.setText("Cancelar");
      buttonCancelarData.setFont(new Font("Arial", Font.PLAIN, 12));
      buttonCancelarData.addActionListener(e -> buttonCancelarDataActionPerformed(e));
      dialogoCalendarContentPane.add(buttonCancelarData);
      buttonCancelarData.setBounds(110, 155, 90, 28);

      dialogoCalendarContentPane.setPreferredSize(new Dimension(225, 235));
      dialogoCalendar.setSize(225, 235);
      dialogoCalendar.setLocationRelativeTo(null);
    }
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
  }
Пример #18
0
  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    // Generated using JFormDesigner Evaluation license - Chance Turner
    mainMenuBar = new JMenuBar();
    maintenanceMenu = new JMenu();
    editStore = new JMenuItem();
    editItem = new JMenuItem();
    editTaxCategory = new JMenuItem();
    editCashier = new JMenuItem();
    editRegister = new JMenuItem();
    menu1 = new JMenu();
    loginToPos = new JMenuItem();
    menu2 = new JMenu();
    dailySalesReportMenuItem = new JMenuItem();
    itemSalesReportMenuItem = new JMenuItem();
    cashierSalesReportMenuItem = new JMenuItem();
    panel1 = new JPanel();

    // ======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(null);

    // ======== mainMenuBar ========
    {

      // ======== maintenanceMenu ========
      {
        maintenanceMenu.setText("Maintenance");

        // ---- editStore ----
        editStore.setText("Edit Store");
        editStore.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                editStoreActionPerformed(e);
              }
            });
        maintenanceMenu.add(editStore);

        // ---- editItem ----
        editItem.setText("Edit Item");
        editItem.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                editItemActionPerformed(e);
              }
            });
        maintenanceMenu.add(editItem);

        // ---- editTaxCategory ----
        editTaxCategory.setText("Edit Tax Category");
        editTaxCategory.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                editTaxCategoryActionPerformed(e);
              }
            });
        maintenanceMenu.add(editTaxCategory);

        // ---- editCashier ----
        editCashier.setText("Edit Cashier");
        editCashier.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                editCashierActionPerformed(e);
              }
            });
        maintenanceMenu.add(editCashier);

        // ---- editRegister ----
        editRegister.setText("Edit Register");
        editRegister.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                editRegisterActionPerformed(e);
              }
            });
        maintenanceMenu.add(editRegister);
      }
      mainMenuBar.add(maintenanceMenu);

      // ======== menu1 ========
      {
        menu1.setText("POS");

        // ---- loginToPos ----
        loginToPos.setText("Login");
        loginToPos.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                loginToPosActionPerformed(e);
              }
            });
        menu1.add(loginToPos);
      }
      mainMenuBar.add(menu1);

      // ======== menu2 ========
      {
        menu2.setText("Reports");

        // ---- dailySalesReportMenuItem ----
        dailySalesReportMenuItem.setText("Daily Sales");
        dailySalesReportMenuItem.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                dailySalesReportMenuItemActionPerformed(e);
              }
            });
        menu2.add(dailySalesReportMenuItem);

        // ---- itemSalesReportMenuItem ----
        itemSalesReportMenuItem.setText("Item Sales");
        itemSalesReportMenuItem.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                itemSalesReportMenuItemActionPerformed(e);
              }
            });
        menu2.add(itemSalesReportMenuItem);

        // ---- cashierSalesReportMenuItem ----
        cashierSalesReportMenuItem.setText("Cashier Sales");
        cashierSalesReportMenuItem.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                cashierSalesReportMenuItemActionPerformed(e);
              }
            });
        menu2.add(cashierSalesReportMenuItem);
      }
      mainMenuBar.add(menu2);
    }
    setJMenuBar(mainMenuBar);

    // ======== panel1 ========
    {

      // JFormDesigner evaluation mark
      panel1.setBorder(
          new javax.swing.border.CompoundBorder(
              new javax.swing.border.TitledBorder(
                  new javax.swing.border.EmptyBorder(0, 0, 0, 0),
                  "JFormDesigner Evaluation",
                  javax.swing.border.TitledBorder.CENTER,
                  javax.swing.border.TitledBorder.BOTTOM,
                  new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
                  java.awt.Color.red),
              panel1.getBorder()));
      panel1.addPropertyChangeListener(
          new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent e) {
              if ("border".equals(e.getPropertyName())) throw new RuntimeException();
            }
          });

      panel1.setLayout(null);

      { // compute preferred size
        Dimension preferredSize = new Dimension();
        for (int i = 0; i < panel1.getComponentCount(); i++) {
          Rectangle bounds = panel1.getComponent(i).getBounds();
          preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
          preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
        }
        Insets insets = panel1.getInsets();
        preferredSize.width += insets.right;
        preferredSize.height += insets.bottom;
        panel1.setMinimumSize(preferredSize);
        panel1.setPreferredSize(preferredSize);
      }
    }
    contentPane.add(panel1);
    panel1.setBounds(0, 0, 580, 415);

    { // compute preferred size
      Dimension preferredSize = new Dimension();
      for (int i = 0; i < contentPane.getComponentCount(); i++) {
        Rectangle bounds = contentPane.getComponent(i).getBounds();
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
      }
      Insets insets = contentPane.getInsets();
      preferredSize.width += insets.right;
      preferredSize.height += insets.bottom;
      contentPane.setMinimumSize(preferredSize);
      contentPane.setPreferredSize(preferredSize);
    }
    pack();
    setLocationRelativeTo(getOwner());
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
  }
Пример #19
0
    private void initComponents() {
      label1 = new JLabel();
      comboBox1 = new JComboBox();
      button1 = new JButton();

      // ======== this ========
      setTitle("SneakyFarmer");
      Container contentPane = getContentPane();
      contentPane.setLayout(null);

      // ---- label1 ----
      label1.setText("Which herb to farm:");
      label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 1f));
      contentPane.add(label1);
      label1.setBounds(10, 10, 125, 35);

      // ---- comboBox1 ----
      comboBox1.setModel(
          new DefaultComboBoxModel(
              new String[] {
                "Guam",
                "Marrentill",
                "Tarromin",
                "Harralander",
                "Ranarr",
                "Toadflax",
                "Irit",
                "Avantoe",
                "Kwuarm",
                "Snapdragon",
                "Cadantine",
                "Lantadyme",
                "Dwarf Weed",
                "Torstol"
              }));
      contentPane.add(comboBox1);
      comboBox1.setBounds(135, 10, 90, 35);

      // ---- button1 ----
      button1.setText("Start Farming!");
      button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 7f));
      contentPane.add(button1);
      button1.setBounds(10, 50, 215, 35);
      button1.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              startActionPerformed(e);
            }
          });

      { // compute preferred size
        Dimension preferredSize = new Dimension();
        for (int i = 0; i < contentPane.getComponentCount(); i++) {
          Rectangle bounds = contentPane.getComponent(i).getBounds();
          preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
          preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
        }
        Insets insets = contentPane.getInsets();
        preferredSize.width += insets.right;
        preferredSize.height += insets.bottom;
        contentPane.setMinimumSize(preferredSize);
        contentPane.setPreferredSize(preferredSize);
      }
      pack();
      setLocationRelativeTo(getOwner());
    }
Пример #20
0
  public void layoutContainer(Container parent) {
    Insets insets = parent.insets();
    int ncomponents = parent.countComponents();
    int nrows = getRows();
    int ncols = getColumns();
    int hgap = getHgap();
    int vgap = getVgap();

    if (nrows > 0) {
      ncols = (ncomponents + nrows - 1) / nrows;
    } else {
      nrows = (ncomponents + ncols - 1) / ncols;
    }

    // Set heights
    int x;
    int y;
    int nFills = 0;
    boolean[] fills = new boolean[nrows];
    int lastFillRow = -1;
    int nComps = parent.getComponentCount();

    y = insets.top;
    for (int row = 0; row < nrows; row++) {
      // Find largest minimum height for this row
      int h = 0;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          h = Math.max(h, c.getMinimumSize().height);
        }
      }
      // Set heights for this row
      x = insets.left;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int w = c.getWidth();
          c.setBounds(x, y, w, h);
          x += w + hgap;
          if (col == 0 && getFillRow(c)) {
            fills[row] = true;
          }
        }
      }
      y += h + vgap;
      if (fills[row]) {
        nFills++;
        lastFillRow = row;
      }
    }

    // Fill heights
    if (nFills > 0 && y < parent.getHeight()) {
      // How much height to add
      int hAdd = (parent.getHeight() - y) / nFills;
      int hAdded = 0;
      for (int row = 0; row < nrows; row++) {
        if (fills[row]) {
          if (row == lastFillRow) {
            // Compensate for rounding error
            hAdd = parent.getHeight() - (y + hAdded);
          }
          for (int col = 0; col < ncols; col++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x, b.y + hAdded, b.width, b.height + hAdd);
            }
          }
          hAdded += hAdd;
        }
      }
    }

    // Set widths
    nFills = 0;
    fills = new boolean[ncols];
    int lastFillCol = -1;

    x = insets.left;
    for (int col = 0; col < ncols; col++) {
      // Find largest minimum width for this column
      int w = 0;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          w = Math.max(w, c.getMinimumSize().width);
        }
      }
      // Set widths for this column
      y = insets.top;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int h = c.getHeight();
          c.setBounds(x, y, w, h);
          y += h + vgap;
          if (row == 0 && getFillColumn(c)) {
            fills[col] = true;
          }
        }
      }
      x += w + hgap;
      if (fills[col]) {
        nFills++;
        lastFillCol = col;
      }
    }

    // Fill widths
    if (nFills > 0 && x < parent.getWidth()) {
      // How much width to add
      int wAdd = (parent.getWidth() - x) / nFills;
      int wAdded = 0;
      for (int col = 0; col < ncols; col++) {
        if (fills[col]) {
          if (col == lastFillCol) {
            wAdd = parent.getWidth() - (x + wAdded);
          }
          for (int row = 0; row < nrows; row++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x + wAdded, b.y, b.width + wAdd, b.height);
            }
          }
          wAdded += wAdd;
        }
      }
    }
  }