import java.awt.*; /** * A layout manager that "cascades" components separated by 20px in each dimension. * Not particularly useful, but an illustration of implementing a custom * layout manager strategy. * @author Marty Stepp * @version CSE 331 Spring 2011, 5/9/2011 */ public class CascadingLayout implements LayoutManager { public void addLayoutComponent(String arg0, Component arg1) {} /** * Lays out the components in the given container in a cascading style from top-left. */ public void layoutContainer(Container container) { int x = 0; int y = 0; for (Component comp : container.getComponents()) { // position/size the component comp.setSize(comp.getPreferredSize()); comp.setLocation(x, y); x += 40; y += 40; } } public Dimension minimumLayoutSize(Container arg0) { return null; } public Dimension preferredLayoutSize(Container arg0) { return null; } public void removeLayoutComponent(Component arg0) {} }