import java.awt.*; /** Note from Francis : This class was one of the simple Vertical FlowLayout * managers I found on the Web, so I shamelessly copied its source code * into my own. It is obviously lacking the proper comments, but this * layout's name is pretty self-explanatory...! * * Creation date: (3/30/2000 4:10:35 PM) * @author: David Risner */ public class VerticalFlowLayout implements LayoutManager { private int vgap = 0; /** * This default constructor creates a Vertical FLowLayout using 0 for the vertical gap between the layed-out components. */ public VerticalFlowLayout() { this(0); } /** This constructor creates a Vertical FLowLayout using the specified vgap value for the vertical * gap between the layed-out components. * @param vgap Vertical gap to be used */ public VerticalFlowLayout(int vgap) { if (vgap < 0) { this.vgap = 0; } else { this.vgap = vgap; } } /** Unimplemented method of the interface * @param name Name * @param comp The component */ public void addLayoutComponent(String name, Component comp) { } /** layoutContainer method comment. * @param parent The parent component */ public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int w = parent.getSize().width - insets.left - insets.right; // int h = parent.size().height - insets.top - insets.bottom; int numComponents = parent.getComponentCount(); if (numComponents == 0) { return; } int y = insets.top; int x = insets.left; for (int i = 0; i < numComponents; ++i) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension d = c.getPreferredSize(); c.setBounds(x, y, w, d.height); y += d.height + vgap; } } } /** minimumLayoutSize method comment. * @param parent The parent component * @return The minimum dimension */ public Dimension minimumLayoutSize(Container parent) { Insets insets = parent.getInsets(); int maxWidth = 0; int totalHeight = 0; int numComponents = parent.getComponentCount(); for (int i = 0; i < numComponents; ++i) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension cd = c.getMinimumSize(); maxWidth = Math.max(maxWidth, cd.width); totalHeight += cd.height; } } Dimension td = new Dimension(maxWidth + insets.left + insets.right, totalHeight + insets.top + insets.bottom + vgap * numComponents); return td; } /** preferredLayoutSize method comment. * @param parent The parent component * @return The preferred size */ public Dimension preferredLayoutSize(Container parent) { Insets insets = parent.getInsets(); int maxWidth = 0; int totalHeight = 0; int numComponents = parent.getComponentCount(); for (int i = 0; i < numComponents; ++i) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension cd = c.getPreferredSize(); maxWidth = Math.max(maxWidth, cd.width); totalHeight += cd.height; } } Dimension td = new Dimension(maxWidth + insets.left + insets.right, totalHeight + insets.top + insets.bottom + vgap * numComponents); return td; } /** removeLayoutComponent method comment. * @param comp The component */ public void removeLayoutComponent(Component comp) { } }