Example usage for java.awt Container getComponentCount

List of usage examples for java.awt Container getComponentCount

Introduction

In this page you can find the example usage for java.awt Container getComponentCount.

Prototype

public int getComponentCount() 

Source Link

Document

Gets the number of components in this panel.

Usage

From source file:CenterLayout.java

/**
 * Lays out the components./*from   w  w w. j  a  va 2  s.  c  o  m*/
 * 
 * @param parent
 *          the parent.
 */
public void layoutContainer(final Container parent) {

    synchronized (parent.getTreeLock()) {
        if (parent.getComponentCount() > 0) {
            final Insets insets = parent.getInsets();
            final Dimension parentSize = parent.getSize();
            final Component component = parent.getComponent(0);
            final Dimension componentSize = component.getPreferredSize();
            final int xx = insets.left
                    + (Math.max((parentSize.width - insets.left - insets.right - componentSize.width) / 2, 0));
            final int yy = insets.top + (Math
                    .max((parentSize.height - insets.top - insets.bottom - componentSize.height) / 2, 0));
            component.setBounds(xx, yy, componentSize.width, componentSize.height);
        }
    }

}

From source file:Main.java

public Dimension minimumLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    int nComps = parent.getComponentCount();

    //Always add the container's insets!
    Insets insets = parent.getInsets();
    dim.width = minWidth + insets.left + insets.right;
    dim.height = minHeight + insets.top + insets.bottom;

    sizeUnknown = false;// ww  w .j av  a 2  s.  c o  m

    return dim;
}

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

/**
 * Lays out the container.//from  w w  w . j av a 2s  . co m
 */
public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    synchronized (parent.getTreeLock()) {
        int n = parent.getComponentCount();
        Dimension pd = parent.getSize();
        //do layout
        int cnt = 0;
        int totalwid = pd.width - insets.left - insets.right;
        int x = insets.left;
        int cumwid = 0;
        for (int i = 0; i < n; i++) {
            Component c = parent.getComponent(i);
            int wid = proportions[i] * totalwid / total;
            c.setBounds(x, insets.top, wid, pd.height - insets.bottom - insets.top);
            x += wid;
            cnt++;
            if (cnt == num)
                break;
        }
    }
}

From source file:Main.java

public Dimension preferredLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    int nComps = parent.getComponentCount();

    setSizes(parent);/*from   w  w  w. ja  v  a 2 s  .  c  om*/

    //Always add the container's insets!
    Insets insets = parent.getInsets();
    dim.width = preferredWidth + insets.left + insets.right;
    dim.height = preferredHeight + insets.top + insets.bottom;

    sizeUnknown = false;

    return dim;
}

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;/*from w  ww.ja  va2s.  c  om*/
                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:XYLayout.java

public void layoutContainer(Container target) {
    Insets insets = target.getInsets();
    int count = target.getComponentCount();
    for (int i = 0; i < count; i++) {
        Component component = target.getComponent(i);
        if (component.isVisible()) {
            Rectangle r = getComponentBounds(component, true);
            component.setBounds(insets.left + r.x, insets.top + r.y, r.width, r.height);
        }/* www . j ava 2  s . c om*/
    }

}

From source file:RadialLayout.java

/**
 * Sets the sizes attribute of the RadialLayout object.
 *
 * @param  parent  the parent./*from  w w w.j ava 2s  . c o  m*/
 * 
 * @see LayoutManager
 */
private void setSizes(final Container parent) {
    final int nComps = parent.getComponentCount();
    //Reset preferred/minimum width and height.
    this.preferredWidth = 0;
    this.preferredHeight = 0;
    this.minWidth = 0;
    this.minHeight = 0;
    for (int i = 0; i < nComps; i++) {
        final Component c = parent.getComponent(i);
        if (c.isVisible()) {
            final Dimension d = c.getPreferredSize();
            if (this.maxCompWidth < d.width) {
                this.maxCompWidth = d.width;
            }
            if (this.maxCompHeight < d.height) {
                this.maxCompHeight = d.height;
            }
            this.preferredWidth += d.width;
            this.preferredHeight += d.height;
        }
    }
    this.preferredWidth = this.preferredWidth / 2;
    this.preferredHeight = this.preferredHeight / 2;
    this.minWidth = this.preferredWidth;
    this.minHeight = this.preferredHeight;
}

From source file:CenterLayout.java

/**
 * Returns the minimum size./*from  w  w  w  .j  a  v a  2s.  com*/
 * 
 * @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:CenterLayout.java

/**
 * Returns the preferred size.//w  ww  . j  av  a 2 s . c  o m
 * 
 * @param parent
 *          the parent.
 * 
 * @return the preferred size.
 */
public Dimension preferredLayoutSize(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.getPreferredSize();
            return new Dimension((int) d.getWidth() + insets.left + insets.right,
                    (int) d.getHeight() + insets.top + insets.bottom);
        } else {
            return new Dimension(insets.left + insets.right, insets.top + insets.bottom);
        }
    }

}

From source file:ColumnLayout.java

/**
 * The method that actually performs the layout. Called by the Container
 *///from   w  ww.j  a  va2s .  c o m
public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    Dimension parent_size = parent.getSize();
    Component kid;
    int nkids = parent.getComponentCount();
    int x0 = insets.left + margin_width; // The base X position
    int x;
    int y = insets.top + margin_height; // Start at the top of the column

    for (int i = 0; i < nkids; i++) { // Loop through the kids
        kid = parent.getComponent(i); // Get the kid
        if (!kid.isVisible())
            continue; // Skip hidden ones
        Dimension pref = kid.getPreferredSize(); // How big is it?
        switch (alignment) { // Compute X coordinate
        default:
        case LEFT:
            x = x0;
            break;
        case CENTER:
            x = (parent_size.width - pref.width) / 2;
            break;
        case RIGHT:
            x = parent_size.width - insets.right - margin_width - pref.width;
            break;
        }
        // Set the size and position of this kid
        kid.setBounds(x, y, pref.width, pref.height);
        y += pref.height + spacing; // Get Y position of the next one
    }
}