// currently doesn't use any gaps or margins sclass VScrollingWrapLayout > AbstractLayoutManager { settable bool centeredHorizontally; public void layoutContainer(Container parent) { L components = getComponents(parent); class X { int maxWidth = parent.getWidth(); int x, y; int lineHeight; int componentsInLine, i; void finishLine { if (centeredHorizontally) { int x1 = (maxWidth-x)/2; for (int j = i-componentsInLine; j < i; j++) { var c = components.get(j); Rectangle r = c.getBounds(); c.setBounds(r.x+x1, r.y, r.width, r.height); } } } void run { for (i = 0; i < l(components); i++) { var c = components.get(i); Dimension size = c.getPreferredSize(); bool needNewLine = componentsInLine != 0 && x+size.width > maxWidth; if (needNewLine) { finishLine(); y += lineHeight; x = componentsInLine = lineHeight = 0; } c.setBounds(x, y, size.width, size.height); x += size.width; lineHeight = max(size.height, lineHeight); ++componentsInLine; } finishLine(); preferredSize(maxWidth, y+lineHeight); } } new X().run(); } }