Example usage for java.awt Container size

List of usage examples for java.awt Container size

Introduction

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

Prototype

@Deprecated
public Dimension size() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:CircleOfSquares.java

public void layoutContainer(Container parent) {

    int rowCount = rows;
    int colCount = hComponentCellWidths.length;
    Insets parentInsets = parent.insets();
    int componentCount = parent.countComponents();

    if (componentCount == 0) {
        return;//from w  w w  .j  a  v a 2s.c  om
    }

    // Calculate the width and height of each grid cell. The height will
    // be the height of each component, but the width may not. The width
    // of a component will be some multiple of a grid cell width. The
    // number of grid cells for each component is defined by the
    // hComponentCellWidths array. w is width of each grid cell. h is
    // height of each grid cell.
    Dimension parentDim = parent.size();
    int w = parentDim.width - (parentInsets.left + parentInsets.right);
    int h = parentDim.height - (parentInsets.top + parentInsets.bottom);
    w /= cols;
    h /= rowCount;

    // For each row and column of components (not grid cells) position
    // the component.
    for (int c = 0, x = parentInsets.left; c < colCount; c++) {
        for (int r = 0, y = parentInsets.top; r < rowCount; r++) {

            int i = r * colCount + c;
            if (i < componentCount) {
                parent.getComponent(i).reshape(x, y, w * hComponentCellWidths[c], h);
            }
            y += h;
        }
        x += (w * hComponentCellWidths[c]);
    }
}