Java JComponent Size sameSize(JComponent[] components)

Here you can find the source of sameSize(JComponent[] components)

Description

same Size

License

Open Source License

Declaration

public static Dimension sameSize(JComponent[] components) 

Method Source Code

//package com.java2s;

import java.awt.Dimension;

import java.util.List;

import javax.swing.JComponent;

public class Main {
    public static Dimension sameSize(List<JComponent> components) {
        JComponent[] array = new JComponent[components.size()];
        array = components.toArray(array);
        return sameSize(array);
    }// www. j a  v  a2s  .  com

    public static Dimension sameSize(JComponent[] components) {
        int width = 0;
        int height = 0;

        for (int i = 0; i < components.length; i++) {
            Dimension size = components[i].getPreferredSize();
            width = Math.max(width, size.width);
            height = Math.max(height, size.height);
        }

        Dimension result = new Dimension(width, height);

        for (int i = 0; i < components.length; i++) {
            components[i].setSize(result);
        }

        return result;
    }

    public static void setSize(Dimension size, JComponent[] components) {
        for (JComponent component : components) {
            component.setSize(size);
        }
    }

    public static void setSize(Dimension size, List<JComponent> components) {
        for (JComponent component : components) {
            component.setSize(size);
        }
    }
}

Related

  1. paint(final Component c, Dimension size)
  2. preferredSize(JComponent component)
  3. resize(JComponent component, Dimension size)
  4. resizeComponentWidth(JComponent currentComponent, double maxComponentWidth)
  5. restrictWindowMinimumSize(final Window wnd, final Dimension minSize)
  6. saveComponentSize(JComponent comp, Preferences prefs, String name)
  7. setAllSizes(JComponent component, int width, int height)
  8. setComponentSize(int width, int height, JComponent l)
  9. setComponentSize(JComponent comp, int defWidth, int defHeight, Preferences prefs, String name)