List of usage examples for java.awt Component preferredSize
@Deprecated
public Dimension preferredSize()
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 {/*w ww .j a v a 2s . c om*/ 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); }