Example usage for java.awt Component getMinimumSize

List of usage examples for java.awt Component getMinimumSize

Introduction

In this page you can find the example usage for java.awt Component getMinimumSize.

Prototype

public Dimension getMinimumSize() 

Source Link

Document

Gets the minimum size of this component.

Usage

From source file:Main.java

public static void constrainResize(ComponentEvent componentevent) {
    Component component = componentevent.getComponent();
    Dimension dimension = component.getSize();
    Dimension dimension1 = component.getMinimumSize();
    Dimension dimension2 = new Dimension(dimension);
    boolean flag = false;
    if (dimension.width < dimension1.width) {
        flag = true;//from   w w  w.  j  a  va 2  s.  com
        dimension2.width = dimension1.width;
    }
    if (dimension.height < dimension1.height) {
        flag = true;
        dimension2.height = dimension1.height;
    }
    if (flag)
        component.setSize(dimension2);
}

From source file:SpringBox.java

/**
 * A debugging utility that prints to stdout the component's minimum,
 * preferred, and maximum sizes./*w  w  w  . ja  v  a2 s  .com*/
 */
public static void printSizes(Component c) {
    System.out.println("minimumSize = " + c.getMinimumSize());
    System.out.println("preferredSize = " + c.getPreferredSize());
    System.out.println("maximumSize = " + c.getMaximumSize());
}

From source file:Main.java

public static Dimension getSize(Component c, int sizeflag) {
    if (c == null) {
        return new Dimension(0, 0);
    }/*from   w  ww.j  a v a 2s.  co  m*/
    //special case due to swing bug: html labels need to know the current parent layout's size
    if (c instanceof JLabel) {
        View v = (View) ((JLabel) c).getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey);
        if (v != null) {
            switch (sizeflag) {
            case MIN: {
                Dimension d = new Dimension(c.getPreferredSize());
                d.width = 1;
                return d;
            }
            case PREF: {
                Dimension d = new Dimension(c.getPreferredSize());
                return d;
            }
            case MAX: {
                Dimension d = new Dimension(10240, 10240);
                d.width = 1;
                return d;
            }
            }
        }
    }
    //
    switch (sizeflag) {
    case MIN: {
        return new Dimension(c.getMinimumSize());
    }
    case PREF: {
        return new Dimension(c.getPreferredSize());
    }
    case MAX: {
        return new Dimension(c.getMaximumSize());
    }
    }
    return new Dimension(c.getPreferredSize());
}

From source file:CenterLayout.java

/**
 * Returns the minimum size./*from w  w  w. j  a va 2 s . c o m*/
 * 
 * @param parent
 *          the parent.
 * 
 * @return the minimum size.
 */
public Dimension minimumLayoutSize(final Container parent) {

    synchronized (parent.getTreeLock()) {
        final Insets insets = parent.getInsets();
        if (parent.getComponentCount() > 0) {
            final Component component = parent.getComponent(0);
            final Dimension d = component.getMinimumSize();
            return new Dimension(d.width + insets.left + insets.right, d.height + insets.top + insets.bottom);
        } else {
            return new Dimension(insets.left + insets.right, insets.top + insets.bottom);
        }
    }

}

From source file:SquareLayout.java

/**
 * Calculates the minimum size dimensions for the specified panel given the 
 * components in the specified parent container. 
 *///w  w w  .j  ava2s .co m

public Dimension minimumLayoutSize(Container container) {
    Component child = getChild(container);
    if (child == null)
        return new Dimension(0, 0);

    Dimension childMinSize = child.getMinimumSize();
    Insets insets = container.getInsets();

    int width = childMinSize.width + insets.left + insets.right;
    int height = childMinSize.height + insets.top + insets.bottom;
    int maxSize = Math.max(width, height);
    return new Dimension(maxSize, maxSize);
}

From source file:com.equitysoft.cellspark.ProportionalLayout.java

private Dimension layoutSize(Container parent, boolean minimum) {
    Dimension dim = new Dimension(0, 0);
    synchronized (parent.getTreeLock()) {
        int n = parent.getComponentCount();
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            Component c = parent.getComponent(i);
            int maxhgt = 0;
            if (c.isVisible()) {
                Dimension d = (minimum) ? c.getMinimumSize() : c.getPreferredSize();
                dim.width += d.width;/*  ww w .  ja  v a2 s.  co m*/
                if (d.height > dim.height)
                    dim.height = d.height;
            }
            cnt++;
            if (cnt == num)
                break;
        }
    }
    Insets insets = parent.getInsets();
    dim.width += insets.left + insets.right;
    dim.height += insets.top + insets.bottom;
    return dim;
}

From source file:RelativeLayout.java

/**
 * Called from AWT to calculate the minimum size dimensions for the target
 * panel given the components in it. But we use our own list of named
 * insertions, not the list of Components that the container keeps.
 * /*from w ww  .  j  a  v  a 2 s .  c  om*/
 * @param target
 *            Container to calculate for
 */
public Dimension minimumLayoutSize(Container target) {
    int minw = 0, minh = 0;
    for (int i = 0; i < curComps.size(); i++) {
        Tracker t = (Tracker) curComps.elementAt(i);
        Component tc = t.getComponent();
        Dimension d = tc.getMinimumSize();
        Point rl = t.getRequestedLoc();
        minw = Math.max(minw, rl.x + d.width);
        minh = Math.max(minh, rl.y + d.height);
        // System.out.println("minLay, minw = " + minw
        // + "; minh = " + minh);
    }
    return new Dimension(minw, minw);
}

From source file:RelativeLayout.java

/**
 * Called by AWT to compute the preferred size for the target panel given
 * our list of the components that it contains.
 * /*ww  w. j  a va2s  .c  o m*/
 * @param target
 *            Container to calculate for
 */
public Dimension preferredLayoutSize(Container target) {
    int prefw = 0, prefh = 0;
    for (int i = 0; i < curComps.size(); i++) {
        Tracker t = (Tracker) curComps.elementAt(i);
        Component tc = t.getComponent();
        Dimension d = tc.getMinimumSize();
        Point rl = t.getRequestedLoc();
        prefw = Math.max(prefw, rl.x + d.width);
        prefh = Math.max(prefh, rl.y + d.height);
        // System.out.println("prefLay, prefw = " +
        // prefw + "; prefh = " + prefh);
    }
    return new Dimension(prefw, prefh);
}

From source file:VerticalLayout.java

private Dimension layoutSize(Container parent, boolean minimum) {
    Dimension dim = new Dimension(0, 0);
    Dimension d;/*ww w  .  ja  va 2  s  . co  m*/
    synchronized (parent.getTreeLock()) {
        int n = parent.getComponentCount();
        for (int i = 0; i < n; i++) {
            Component c = parent.getComponent(i);
            if (c.isVisible()) {
                d = minimum ? c.getMinimumSize() : c.getPreferredSize();
                dim.width = Math.max(dim.width, d.width);
                dim.height += d.height;
                if (i > 0)
                    dim.height += vgap;
            }
        }
    }
    Insets insets = parent.getInsets();
    dim.width += insets.left + insets.right;
    dim.height += insets.top + insets.bottom + vgap + vgap;
    return dim;
}

From source file:LCBLayout.java

/**
 * Returns the minimum size using this layout manager.
 *
 * @param parent  the parent./*from www. j  ava 2 s.com*/
 *
 * @return the minimum size using this layout manager.
 */
public Dimension minimumLayoutSize(final Container parent) {

    synchronized (parent.getTreeLock()) {
        final Insets insets = parent.getInsets();
        final int ncomponents = parent.getComponentCount();
        final int nrows = ncomponents / COLUMNS;
        for (int c = 0; c < COLUMNS; c++) {
            for (int r = 0; r < nrows; r++) {
                final Component component = parent.getComponent(r * COLUMNS + c);
                final Dimension d = component.getMinimumSize();
                if (this.colWidth[c] < d.width) {
                    this.colWidth[c] = d.width;
                }
                if (this.rowHeight[r] < d.height) {
                    this.rowHeight[r] = d.height;
                }
            }
        }
        int totalHeight = this.vGap * (nrows - 1);
        for (int r = 0; r < nrows; r++) {
            totalHeight = totalHeight + this.rowHeight[r];
        }
        final int totalWidth = this.colWidth[0] + this.labelGap + this.colWidth[1] + this.buttonGap
                + this.colWidth[2];
        return new Dimension(insets.left + insets.right + totalWidth + this.labelGap + this.buttonGap,
                insets.top + insets.bottom + totalHeight + this.vGap);
    }

}