Java JComponent Size preferredSize(JComponent component)

Here you can find the source of preferredSize(JComponent component)

Description

preferred Size

License

Open Source License

Declaration

public static Dimension preferredSize(JComponent component) 

Method Source Code

//package com.java2s;

import java.awt.Dimension;

import java.util.List;

import javax.swing.JComponent;

public class Main {
    public static Dimension preferredSize(JComponent component) {
        Dimension size = component.getPreferredSize();
        component.setSize(size);/*from  www . j  a va 2 s .  c  o m*/
        return size;
    }

    public static Dimension preferredSize(JComponent component,
            int overrideWidth, int overrideHeight) {
        Dimension size = component.getPreferredSize();

        if (overrideWidth != -1) {
            size.width = overrideWidth;
        }

        if (overrideHeight != -1) {
            size.height = overrideHeight;
        }

        component.setSize(size);
        return size;
    }

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

    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. makeSameSize(Component... components)
  2. makeSameSize(JComponent... comps)
  3. makeSameSize(JComponent[] comps)
  4. minSize(T comp, int width)
  5. paint(final Component c, Dimension size)
  6. resize(JComponent component, Dimension size)
  7. resizeComponentWidth(JComponent currentComponent, double maxComponentWidth)
  8. restrictWindowMinimumSize(final Window wnd, final Dimension minSize)
  9. sameSize(JComponent[] components)