List of usage examples for java.awt Container insets
@Deprecated
public Insets insets()
From source file:CircleOfSquares.java
public Dimension minimumLayoutSize(Container parent) { Insets parentInsets = parent.insets(); int componentCount = parent.countComponents(); int rowCount = rows; int colCount = cols; if (rowCount > 0) { colCount = (componentCount + rowCount - 1) / rowCount; } else {/*from w w w .j av a2 s. co m*/ rowCount = (componentCount + colCount - 1) / colCount; } // Find the maximum "minimum width" and the maximum "minimum height" // of any component. int w = 0; int h = 0; for (int i = 0; i < componentCount; i++) { Component comp = parent.getComponent(i); Dimension d = comp.minimumSize(); if (w < d.width) { w = d.width; } if (h < d.height) { h = d.height; } } // Return the maximum "minimum component width and height" times the number // of columns and rows, respectively, plus any insets in the parent. return new Dimension(parentInsets.left + parentInsets.right + colCount * w, parentInsets.top + parentInsets.bottom + rowCount * h); }
From source file:CircleOfSquares.java
public Dimension preferredLayoutSize(Container parent) { int rowCount = rows; int colCount = cols; Insets parentInsets = parent.insets(); int componentCount = parent.countComponents(); if (rowCount > 0) { colCount = (componentCount + rowCount - 1) / rowCount; } else {//from w ww . j a v a 2 s . c o m rowCount = (componentCount + colCount - 1) / colCount; } // Find the maximum preferred width and the maximum preferred height // of any component. int w = 0; int h = 0; for (int i = 0; i < componentCount; i++) { Component comp = parent.getComponent(i); Dimension d = comp.preferredSize(); if (w < d.width) { w = d.width; } if (h < d.height) { h = d.height; } } // Return the maximum preferred component width and height times the number // of columns and rows, respectively, plus any insets in the parent. return new Dimension(parentInsets.left + parentInsets.right + colCount * w, parentInsets.top + parentInsets.bottom + rowCount * h); }
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;/*ww w.java 2s .com*/ } // 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]); } }